I have a database and I used to backup daily manually like so
mysqldump -uroot -ppassword forum > 4.25.2011.sql
However I’ve been doing the above and wanted to use a script besides mysqldumper to do the job.
If 3 existing .sql files exist in the backup directory, how can I delete the oldest one?
So far all I have is:
#!/bin/bash
today = `eval date +%m.%d.%Y` #how do I add this to the backup?
mysqldump -uroot -ppassword forum > /root/backups/4.25.2011.sql
I still can’t figure out how to pass a variable to save my sql file as. How would I do that too?
My VPS is limited to 10gb and disk size is a concern or else I wouldn’t delete any files.
For your first part, instead of
do
In particular:
The simplest way to only keep three files would be:
Tools like
ls -lor the content of the file should tell you the date if you need it.If you really need the date in the file name, the easiest tool to help you is GNU date:
Or use
find, e.g.After that, you could look at logrotate.