LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Need tips on creating scripts for daily backup (tar) a directory to an external drive (https://www.linuxquestions.org/questions/linux-server-73/need-tips-on-creating-scripts-for-daily-backup-tar-a-directory-to-an-external-drive-559866/)

Joejr4u 06-07-2007 05:09 AM

Need tips on creating scripts for daily backup (tar) a directory to an external drive
 
Hi,

I need some tips on creating a script for daily backup of a large directory with tar to an external scsi drive.

The problem here is that, i need to have the script find the oldest tar archive and remove it so as to free space on the drive once its full (the size of the directory is between 80 and 100GB) and the size of the external drive is 500GB.

Also need to have a log file to keep track of the backup cuz i'm execute it as a cron job to run at night.

Would really appreciate ur kind suggestions? If possible an example script wuld help me speed things up. Its kinda urgent as i have to have it ready 2morow.

Thanks anyone.

Silverhawk.

kees-jan 06-07-2007 06:52 AM

Remove the oldest file
Code:

rm "$(ls -rt | head -1)"
Remove all files, except the three most recent ones
Code:

rm $(ls -t | sed -e '1,3d')
Note that for this last example, filenames cannot have spaces

Groetjes,

Kees-Jan

fayez 06-07-2007 07:46 AM

Or you can use the find command:

#find /bigdir -mtime +n -exec rm {}\;

where n is days, for example if you want to remove files created before 2 days replace n by 2. to be sure about the functionality of this command try it first with ls command:
#find /bigdir -mtime +n -exec ls -ltr {}\;


All times are GMT -5. The time now is 01:52 AM.