What's the easiest way to auto-backup an EC2 instance? [duplicate]
Solution 1:
I have all my application code, db, configuration and log files sitting on a seperate EBS volume that i mount on /dev/sdf. You can create an initial snapshot of this and then mount this to your os at runtime. My ami just contains the relevent stuff to autostart the environment.
ec2-run-instances ami-id <other options> --block-device-mapping '/dev/sdf=snap-id::false'
The volume that this creates can be backed up fairly easily using crontab and ec2-create-snapshot or whatever. ec2-describe-snapshot gives the date of snapshot creation, so that can be used with awk or whatever to figure out which one's to delete. Although snapshot's only record the change between versions, so after the first one they don't actually take up too much space.
Solution 2:
I'd suggest giving my "ec2-automate-backup" tool a try and running this under cron. You'd run the command as follows ec2-automate-backup -v your_volumeid -k 7 -p
. The options here tell the tool: which volumes to backup (-v your_volumeid) the number of days you wish to keep backups (-k 7) and to purge old volumes (-p). The tool is freely available and open source.
If you need to backup more than one volume, you'd "tag" each volume using AWS Tags and then run as follows ec2-automate-backup -s tag -t "Backup=your_tag" -k 7 -p
. The options here are: -s tag (-s tag tells ec2-automate-backup
to select volumes for backup by tag) and -t "Backup=your_tag" tells ec2-automate-backup
to backup volumes tagged "your_tag."
ec2-automate-backup is part of AWS-Missing-Tools, available at http://awsmissingtools.com
Solution 3:
I have created a small wrapper script which does the following:
-dumps the DB (it is small, takes seconds)
-creates a tarball but only the diff between yesterday and today or a full backup if the day is Sunday
-invokes hg addremove && hg commit on /etc and the webroot (ignore file is pretty smart)
-uploads the previously created files to S3
This is not a full backup because it excludes the operating system. But since all my configuration files are saved, I don't care. This is a cost efficient way to make sure everything is available, even the history for certain things like the database.
Hope that helps.