Operating System - HP-UX
1833838 Members
2177 Online
110063 Solutions
New Discussion

How to selectively restore files by script

 
SOLVED
Go to solution
Marcin Piwko
Advisor

How to selectively restore files by script

Hello All,
I have 'easy' problem but I hope interesting for you:

there is backup repository, say /backup/PROD.
And there is production, say /u1/PROD.

Layout of files on /backup reasembles layout of files (and dirs) on prod, i.e.:

file /u1/PROD/file1 goes to /backup/PROD/u1/PROD/file1 during backup.

Backup is done at 6PM, production then makes processing. Incase of this processing failure I would like to create restore script, which would restore only those files from /bakup to production, which has been changed on production since backup time.

I have tried:
find /u1/PROD -type f -mtime -1 -exec cp /backup/PROD{} {} \;
but with no luck.
first problem: it gets files modified during past 24hrs, but I need only files newer than 6PM the day before (or the same day in case we need to restore before midnight)
second problem: it does not concatenize path of running file {} with /backup/PROD base and shows error "/backup/PROD/{} not found".

Please advice is it a good way or what should be corrected.

Regards,
Martin P
3 REPLIES 3
Pete Randall
Outstanding Contributor
Solution

Re: How to selectively restore files by script

I would suggest using the touch command to create a file with the time stamp of yesterday at 6:00, then using the find command with the -newer option to select just the files you are interested in. Refer to "man find" and "man touch".


Pete

Pete
Steve Steel
Honored Contributor

Re: How to selectively restore files by script

Hi

Your backup must write a logfile so use the -newer in find on the logfile


-newer[tv1[tv2]] file True if the indicated time value (tv1) of the
current file is newer than the indicated time
value (tv2) of file. The time values tv1 and
tv2 are each selected from the set of
characters:

- 4 - Formatted: July 11, 2001

find(1) find(1)

a The time the file was last accessed
c The time the inode of the file was
last modified
m The time the file was last modified



That will give the correct files


do not use the exec option
but

find options|while read line
do
echo cp /backup/PROD/$(basename $line) $line
done


The echo is to check

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Marcin Piwko
Advisor

Re: How to selectively restore files by script

thank you both
Pete: it was so obvious and brilliant I am ashamed, the reason I did not invented that no matter which file is on backup, only the date/time matters, is that I have been digging into it last night at 2AM, awaken by application administrator requesting restore. While wathcing 3 hrs of sensless full restore I tried to figure out better way.
Your way is also good becaulse if the file was created during processing (is missing on backup) it would get listed as an error, which may be usefull to clean up production before restarting processing. Excellent.

Steve: yours is much faster than exec, but I would not make a logfile, becaulse all files go on backup anyway (it makes FULL).

Thank you both