Amazon S3 services is a wonderful fast and good service to backup your databases. This script dumps currently only one, database and uploads the file to a s3 bucket.
- Make your self an Amazon AWS account if you dont already have one. 2.Create a new bucket for your backups (https://console.aws.amazon.com/s3/home).
- (optional) Maybe you want also create a lifecycle policy for example to delete all backups older than 30 days or so. Just edit the properties of the bucket.
- Create a new user in the IAM an give him the policy AmazonS3FullAccess.
- Remember to download the access key and the secret key, you will need them soon.
This are the instructions for Ubuntu, for other distributions they may vary.
# Install s3cmd sudo apt-get -y install python-setuptools wget http://netix.dl.sourceforge.net/project/s3tools/s3cmd/1.6.1/s3cmd-1.6.1.tar.gz tar xvfz s3cmd-1.6.1.tar.gz cd s3cmd-1.6.1 sudo python setup.py install # Configure s3cm (have your access keys ready!) s3cmd --configure
Upload a copy of s3backup.sh (make sure you edit the configurations in the first lines), make it executable and test it
# Add the executable bit chmod +x s3backup.sh # Run the script to make sure it's all working flawless ./s3backup.sh
Edit the crontab (if you first start crontab it will ask you to choose an editor, just use nano it is the best)
crontab -e # Add the following lines: # Run the database backup script at 3am every night 0 3 * * * bash /var/www/s3backup.sh >/dev/null 2>&1
If you have found an error or have an idea to improve the script feel free to comment or make a fork. And please please give me a star.