Recently the World Cup has come, has been busy between work and the World Cup, there is no time to manage my blog, today can only be the whole simple small shell to everyone. The company asked to delete one months before the backup file, so that the hard drive to the whole explosion, on the server looked down, incredibly have 3 months of backup did not clean up, Fortunately, SQL backup, otherwise hard disk space is already full.
Here is my solution:
Cat delbak.sh
#!/bin/sh
location= "/root/sqlbak/"
Find $location-mtime +30-type f |xargs rm-f
Ps:
Location is the directory where you set up the lookup
--mtime +30 is set to a time of 30 days ago
-type F this week the type of lookup is a file
Then add the crontab timer to remove
Crontab-l
4 1 * */bin/sh/root/soft_shell/delbak.sh
Set to 1th per month to execute the script at 4:10 in the evening. Of course, you can do it according to your own needs.
The same deletion method:
Find/root/sqlbak-mtime +30-type f-name *.gz-exec rm-f {}\;