Restoring files from backup based on ctime


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Restoring files from backup based on ctime
# 1  
Old 03-12-2013
Restoring files from backup based on ctime

Hello, I need to restore some yesterday emails from backup within a 5 hours timeframe

this is a openvz container, backup is made by rsync files to another partition in the same server

I have tried to do this

Code:
#!/bin/sh

cd /vz/backup/414/home/smartftp/mail/domain1.com/
for dir in new cur
do
    for dir2 in $(find /vz/backup/414/home/smartftp/mail/domain1.com/*/$dir -type d )
    do

// Replace the folder name
dir3 =$({$dir2/backup/private})
find $dir2 -type f -mmin -840 -mmin +540 -name "*host.*" -exec rsync -av $dir2 $dir3 \;
    done
done

But I am stuck trying to replace the folder name to rsync the files to the working dir from backup to private

Please advice

Last edited by vbe; 03-12-2013 at 10:32 AM.. Reason: code not icode (tags that is hehe...)
# 2  
Old 03-12-2013
I guess there is something about the actual dir structure that keeps this from infinite recursion? New has a dir new under it and cur has a dir cur under it? I get lost quick. How does the find exec act on the file found, no {}?

Last edited by DGPickett; 03-12-2013 at 02:58 PM..
# 3  
Old 03-12-2013
The problem here is not the recursion that works on the backup side only, neither creation of folders as find is only searching for files in the two folders new and cur.

The problem is how to modify the folder path rsync parameter from "backup" to "private"

i guess it is just matter of good shell variables handling but I am not an expert on this, so I just have the logic but not the actual command to turn this parameter from

/vz/backup/other/folders

to

/vz/private/other/folders

i tried parameter expansion but it fails

dir3 =$({$dir2/backup/private})
# 4  
Old 03-12-2013
Well, rsync is just scp/rcp on steroids, so you can do it yourself file by file or -r tree by tree.
# 5  
Old 03-12-2013
Well, scp would do the job, but still do not solve the main question.

How do I replace this location on the variable from backup/ to private/ ?

Any suggestions ?
# 6  
Old 03-13-2013
try something like this in your code.

Code:
 echo ${dir2/backup/private}
/vz/private/414/home/smartftp/mail/domain1.com/

# 7  
Old 03-14-2013
I have the impression you can simplify your script. DGPickett already mentioned it: the files are copied multiple times.
If you have GNU find then the following could work:
Code:
#!/bin/bash
srcdir=/vz/backup/414/home/smartftp/mail/domain1.com
dstdir=/vz/private/414/home/smartftp/mail/domain1.com
cd $srcdir || exit # fatal
find */{cur,new} -type f -mmin -840 -mmin +540 -name "*host.*" -print0 |
 xargs -0 rsync -av $dstdir

For testing, have rsync --dryrun -av ....

Last edited by MadeInGermany; 03-14-2013 at 04:34 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search files between date ranges - Ctime usage

Hello, I am a noob and need some help. I am trying to find files created between a date range. For Example: These are files in directory. -rw-r--r-- 1 user staff 6 May 8 09:43 file1.txt -rw-r--r-- 1 user staff 6 May 8 09:43 file2.txt -rw-r--r-- 1 user... (8 Replies)
Discussion started by: r@v!7*7@
8 Replies

2. Solaris

Restoring a system from a backup

I have backed up the contents of my Solaris 10 machine in its entirety, and I'm trying to figure out if I can somehow use this archive to restore my old system just as it was on a new machine. Assuming I have all files from my old machine backed up, is this possible? What I've been trying to do... (6 Replies)
Discussion started by: unblockable
6 Replies

3. UNIX for Dummies Questions & Answers

[SOLVED] Restoring differential backup files

I'm using a script (automysqlbackup) to dump mysql db's to .sql file followed by taking one full backup of the .sql file and the differential backups of the newer sql file every day using the tool diff. Now the backup destination folder contains files like, I would like to how do i restore... (3 Replies)
Discussion started by: csengineer
3 Replies

4. AIX

restoring mksysb backup of a clustered server configured in HACMP

Hi, I have done NIM restoration via nim_bosinst a lot of times but I have some doubts on restoring a server which is clustered specifically HACMP. Previously, I don't know the trend but after doing a nim_bosinst, I can see the client's hostname is back to "localhost" rather than its original... (0 Replies)
Discussion started by: depam
0 Replies

5. UNIX for Advanced & Expert Users

how to make a full system backup excluding data and restoring it to a new system

Hi, In order to have a sand box machine that I could use to test some system changes before going to production state, I'd like to duplicate a working system to a virtual one. Ideally, I'd like to manage to do it this way : - Make a full system backup excluding the user file system (this... (7 Replies)
Discussion started by: pagaille
7 Replies

6. AIX

Question about restoring from mksysb backup

Hello, Last night I applied a DB2 fix pack which is now causing problems with the application that uses db2. Prior to applying the fix pack I did a mksysb(rootvg) which includes the file system that has db2 installed on it. If I do a restore from this will it restore the db2 version back to... (1 Reply)
Discussion started by: jyoung
1 Replies

7. UNIX for Advanced & Expert Users

restoring backup using tar command

Please help me in resolving the issue. I have taken backup using the below command $ tar cvf - . |compress -> /opt/globusback2/needed_backups/apglsg.tar.Z I tried to restore the backup using the below command. $ zcat /opt/globusback2/needed_backups/apglsg.tar.Z | tar -xvf - ... (5 Replies)
Discussion started by: amirthraj_12
5 Replies

8. UNIX for Dummies Questions & Answers

restoring backup using tar command

Please help me in resolving the issue. I have taken backup using the below command $ tar cvf - . |compress -> /opt/globusback2/needed_backups/apglsg.tar.Z I tried to restore the backup using the below command. $ zcat /opt/globusback2/needed_backups/apglsg.tar.Z | tar -xvf - ... (2 Replies)
Discussion started by: amirthraj_12
2 Replies

9. OS X (Apple)

OS X Server: Trouble restoring mail from backup...

So I had some bad RAM in my server. Of course I didn't know it at the time. And it kept making the 10.3.5 updater crash. And that last crash did it. My drive was messed up. So I had to reformat and reinstall. Luckily I had a whole slew of fresh backups. But I'm really hung up on the mail. I backed... (0 Replies)
Discussion started by: l008com
0 Replies
Login or Register to Ask a Question