Reputation: 13
I have moved my first site to a EC2 micro instance, now the project is working I am trying backup database and images folder, if possible inside Amazon (Glacier? S3?). I have read a lot about it, but I am sure anyone has scripted this before.
Stack: - Ubuntu Server 12.04 LTS - Apache 2.2.1 - PHP 5.4.4
Upvotes: 1
Views: 2457
Reputation: 13065
Generally, you want to use EBS snapshots as your first line of defense. Make a script that creates an EBS backup once per day and deletes the older ones. Put it in cron.
You can consider S3 if you want "extra insurance" in case EBS/EC2 have massive problems. Use s3sync
as pointed out in the other answers. It's best to use compression. There is no "cost sharing" between backups like there is with EBS snapshots.
Glacier has a very long wait time for restoring (many hours) and a minimum restore time (you get a penalty if you restore before 90 days). Therefore, you should only look into it if you want to store a lot of backups for a long time. You cannot use this for disaster recovery, unless you're fine with being down for hours.
Upvotes: 1
Reputation: 22
it´s very basic script, these are the steps:
EXAMPLE SCRIPT TO MYSQLDUMP AND PUSH IT TO S3
#!/bin/bash
MY_FOLDER="/__PATH_TO_WRITABLE_FOLDER__/"
NOW="`date +%Y-%m-%d-%R`"
FILE=$MY_FOLDER"___FILE_NAME___"$NOW".sql"
mysqldump -h localhost -u USER_DB -pPASSDB -c --add-drop-table --add-locks --quick --lock-tables DBNAME > $FILE
s3cmd put $FILE s3://___YOUR_BUCKET_NAME___
echo "`date -u`" "BACKUP DONE - MySQL uploaded to hipespace ^^ -> ".$FILE >> /var/log/my_backups_to_s3
NOTES:
anyway this is only to backup the db, give a try to s3cmd docs, they have another command "sync" that you can user to push your images,
hope it helps
Upvotes: 0
Reputation: 19563
This is rather easy to do. You probably want to use s3 for now.
s3cmd
. It may already be available in your repositoriesYou can script all this together into a simple bash script an execute it with cron on a regular interval. Keep in mind that backups do impact performance somewhat, and should be scheduled during off peak periods.
Upvotes: 0