0

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?

Kenster
  • 23,465
  • 21
  • 80
  • 106
Spencer Mark
  • 5,263
  • 9
  • 29
  • 58

1 Answers1

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