I'm am dumping a mysql wordpress database everyday as a backup. Since i don't want to end up with 365 .sql files after a year, i figured it would be decent only to keep the last 30 days of dump files. Always keep the last 30 and automatically delete the older ones, one a day.
I am looking to program this in bash as part of a cron job. So i already have the part where i dump and send the file to the backup server. I only need to add the counting and deleting the oldest one each day snippet.
Here is what i got (the username and pswd are kept in a .my.cnf file):
now=$(date +'%m-%d-%y')
mysqldump -h mysql.server.com my_database | gzip -9 > ${home}/dbBackups/db_backup.sql.gz
mv ${home}/dbBackups/db_backup.sql.gz ${home}/dbBackups/${now}_db_backup.sql.gz
scp ${home}/dbBackups/${now}_db_backup.sql.gz backup_user@backup.server.com:/home/backup_user/backup.server.com/dbBackups/
Does anyone have an idea on how to implement this functionality?