I'm trying to create a cron job to create mysql backups. I would like to be able to first check how many files are there in the directory and if there are 5 or more remove one (the oldest) and create a new mysqldump. I know how to create the mysqldump, but not sure about the condition. I'm planning to store the procedure in the .sh file and trigger that file once a day with the cronjob. Could someone show the example of what the procedure should look like?
Asked
Active
Viewed 136 times
0
-
And what your question is? – Eugene Mayevski 'Callback Jan 13 '13 at 10:02
-
Just updated the question - with the question :) – Spencer Mark Jan 13 '13 at 10:04
1 Answers
0
You could wrap the following in a shell script
for file_to_delete in `ls -1ta test* | tail --lines=+6` ; do echo "ENTER_CMD_HERE $file_to_delete" ; done
where
- test is name of file (replace it with path + name of the mysql bkp files)
- replace ENTER_CMD_HERE with say rm

souser
- 5,868
- 5
- 35
- 50