script to compress a directory and then delete older than 7 days
I have been trying to write a script that will take a directory, for example /accounts compress it into a .tar file with the filename containing the date of compression, for example accounts030210.tar and then place that file into a directory called /archive
I also want the script to delete files in /archive that are older than 7 days. I have give it ago but suspect I went around it completely the wrong way, I would appreciate any help you could give me. Thanks |
That's a reasonably straightforward script. Rather than asking us to give it to you, why not post what you did and ask for advice and corrections? That's a better learning process. Start by doing the individual commands by hand to see that they work as expected. Then put them in a script and test the script. Use the man pages. Start out with `man tar`, `man date`, and `man find`. Those will give you everything you need.
|
Yes, I need to get in the habit of reading those man pages
Code:
|
If you want a gzipped file, you need to use the correct flag (-z) and I don't know why you'd use -v (verbose) twice or indeed even once in a program.
Also, why not use this date format for natural sorting: YYYYMMDD Code:
tar -czf /archive/backup_`date +%Y%m%d`.tar.gz /accounts/ |
All times are GMT -5. The time now is 12:49 PM. |