I have a script, backup.sh, that creates a backup of a MySQL database and then SCPs it to a remote server. This works great, and I can run this once per day using crontab with no problems.
However, I want to only store the last 30 days of backups, otherwise after a few months I will have hundreds of redundant SQL files. I don't really know where to start with this. The only method I can think of is to have 31 subfolders, one for each of the days of the month, and then replace each file each day. That's slightly less than ideal though, and feels a little dirty.
Below is the contents of my backup.sh file, with some key info obviously removed:
#!/bin/bash
today=`date +%Y-%m-%d.%H%M%S`
mysqldump -u rails -p******** rails > backups/backup-$today.sql
sshpass -p '********' scp backups/backup-$today.sql m***d@******.co.uk:custom_backups/backup-$today.sql