1829104 Members
5160 Online
109986 Solutions
New Discussion

shell scripting

 
hari prasad_4
Advisor

shell scripting

Hi guys,

i need some help on shell scripting, currently i have written one script which take backup of some files and place it on one of the other partition with date and time stamp specified on the file name.

i want to know how to make retention period for the same.

shell script is given below

!#/bin/sh
FILENAME=`date +3dpl_lv0_%Y%m%d%H%M`
cp /essbdata1/levzerodata/lev03dpl.txt /essbdata1/back-hyp/${FILENAME}.txt
tar -cvf ${FILENAME}.tar ${FILENAME}.txt
gzip ${FILENAME}.tar

thanks in advance
9 REPLIES 9
Kenan Erdey
Honored Contributor

Re: shell scripting

you can write and another script and which checks the period you specified, and delete archives which passsed retention time. then you can put it in cron.
Computers have lots of memory but no imagination
Peter Godron
Honored Contributor

Re: shell scripting

Hari,
if you want to keep the tar file for 28 days:

cd tar-directory
find . -mtime +28 -exec rm -f {} \;


This finds and removes ALL files which have not been modified in the last 28 days. This also includes any sub-directories.

see man find for more details
Antonio Cardoso_1
Trusted Contributor

Re: shell scripting

Hi,
You may use cp -p to preserve date and time of file modifications, and then use 'find -mtime ' to manage retention period.

HTH,
antonio.
hari prasad_4
Advisor

Re: shell scripting

hi,
if you check the file name, it has been given as year month date hour and minute.

So based on that i need to check the file name.

thanks
Peter Godron
Honored Contributor

Re: shell scripting

Hari,
if you want to use the filename date, you could download a. Clay Stephensons caljd.sh
at http://mirrors.develooper.com/hpux/caljd-2.23.sh
and use the convert date to julian function.
Subtract the filename date from the current date and you would get the "age" of your file.
hari prasad_4
Advisor

Re: shell scripting

hi,

did you try this script can you let me know how this work, bcoz i need to implement those script in production and live servers

thanks
Peter Godron
Honored Contributor

Re: shell scripting

Hari,
download the latest version caljd-2.25.sh from the same directory and save it as caljd.sh
caljd.sh -help for more help
For your example:
$ ./caljd.sh -y 2006 04 18
2453844
For example if the filedate was 2006 05 17
$ ./caljd.sh -y
2453843

then subtract one from the other and you have the difference in days between the current date and the filename date.

hari prasad_4
Advisor

Re: shell scripting

thanks for all of your help
hari prasad_4
Advisor

Re: shell scripting

..