Operating System - HP-UX
1752800 Members
5608 Online
108789 Solutions
New Discussion юеВ

Re: show date 7 days back for backup

 
Ratzie
Super Advisor

show date 7 days back for backup

I am backing up date base files.
The RMAN will remove obsolete older than 7 days.

So before I start my RMAN I want gtar -cvzf the files and off load to storage.

How can I give the title of the gzip file that is 7 days back?

So far I have:
FILES=$(find . -type f -mtime +7)
gtar -cvzf /backups/foo.tgz $FILES


Or can I get it to find files that are ONLY 7 days old.

Also, I want to set the file name for the .tgz file to <7daysold>_backup.tgz
Have no idea.



4 REPLIES 4
Suraj K Sankari
Honored Contributor

Re: show date 7 days back for backup

Hi,
You can do like this also

find . -atime 7 -exec gzip {} \;
find . -atime 7 -exec tar -cvf backup.tar {} \;| gzip backup.tar

Suraj
Dennis Handly
Acclaimed Contributor

Re: show date 7 days back for backup

>I want to set the file name for the .tgz file to <7daysold>_backup.tgz

It would just be easier to use the current date and note that it is for the previous 7 days. You can also add that to the name of the file, X-7days.tgz

Clay's caljd script may help:
http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1158025

>Suraj: find . -atime 7 -exec tar -cvf backup.tar {} \;| gzip backup.tar

The use of tar with find isn't apt to work if there are lots of files. Instead use pax(1):
find . -atime +7 | pax -w | gzip > backup.tgz
Arturo Galbiati
Esteemed Contributor

Re: show date 7 days back for backup

Hello Ratzie,

1) to get files that are ONLY 7 days old (take care that this is a modify date not the cretaion date) you have to correctly use the find -mtime option. -mtime option is based on 24 hours, cases are:
find . -mtime 0 # find files modified within the past 24 hours
find . -mtime -1 # find files modified within the past 24 hours
find . -mtime 1 # find files modified between 24 and 48 hours ago
find . -mtime +1 # find files modified more than 48 hours ago

so for you: find -mtime 7

2) to get 7 days ago date you can use the caldj script. Refer to A. Clay Stevenson's script 'Date Hammer' which is found at the bottom of this link:
http://mirrors.develooper.com/hpux/

HTH,
Art


Ratzie
Super Advisor

Re: show date 7 days back for backup

I went with parsing the actual date, to confirm I can get the actual files for that date.