I have written a script which takes MySQL dumps and uploads it to Amazon S3. I have added the script to the cronjob and it runs at 2 o'clock in the midnight and uploads the MySQL dump to S3. I am using the date and time stamp as the file name before uploading it to S3.
My problem is I need to manage backups of 7 days on S3 and automatically I have to delete the 8th day backup file from S3 since I am using the date and time stamp as file name to make each file unique, I am not able to figure out how to do it.
And also I have to restore the latest backup in another EC2 instance.
date can help you in figuring out the right 7 day old filename:
Use the following script to rotate the backups after N number of days:
This script needs some modification, i took it from here.
http://www.cyberciti.biz/tips/ssh-rotate-backup-shell-script.html
You can read the complete article to understand it and modify it according to your needs.
Besides all of it, i would recommend you to use Rsnaphot or Bacula backup for automated backup and recovery.
If you only need 7 days of backups you could use the "weekday name" (%A or %a) or the "day of week" number (%w) with date and let the S3 upload replace last week's file.