This is really helpful to Sys-Admin who is managing various backup on different geographical locations.
For Linux,
The following commands will help you to remove your old backup which cost disk usage. I used this script to remove the older backup using a cronjob.
[root@ip-8-11-50-231 database]# crontab -l
00 04 1,16 * * /usr/bin/find /home/remoteftp/database/* -mtime +30 -exec rm {} \;
This cron job will check and delete the files which are older than 30 days.
For Windows,
I uses the command “forfiles” to do.
FORFILES [/P pathname] [/M searchmask] [/S] [/C command] [/D [+ | -] {MM/dd/yyyy | dd}]
Description: Selects a file (or set of files) and executes a command on that file. This is helpful for batch jobs.
Parameter List:
/P : pathname, Indicates the path to start searching. The default folder is the current working directory (.).
/M : searchmask, Searches files according to a searchmask. The default searchmask is ‘*’ .
/S : Instructs forfiles to recurse into subdirectories. Like “DIR /S”.
/C : command Indicates the command to execute for each file. Command strings should be wrapped in double
/D : date, Selects files with a last modified date greater than or equal to (+), or less than or equal to (-), the specified date using the “MM/dd/yyyy” format; or selects files with a last modified date greater than or equal to (+) the current date plus “dd” days, or less than or equal to (-) the current date minus “dd” days. A valid “dd” number of days can be any number in the range of 0 – 32768. “+” is taken as default sign if not specified.
I have create batch file and add the following line in to it. I added some other location on the same server to delete other backup also using the same batch file. I use the ftp to push the backup to this location ( >zip files)and set a scheduler to execute this batch file once in every month.
Here is my batch file content and I uses Windows 2003 server.
rem " removing Web backup which is older thant 30 days>
forfiles /P D:\FTP\LocalUser\svrbkp\live\webfiles /s /D -30 /M *.zip /C " cmd /c del @path"
forfiles /P D:\FTP\LocalUser\svrbkp\live\database /s /D -30 /M *.zip /C " cmd /c del @path "
</code