This article describes how to back up data on your A2 Hosting account to Amazon S3 (Simple Storage Service), as well as how to restore data from Amazon S3 to your account. Using this configuration, your data is backed up securely to an off-site storage location.
To access Amazon S3 services on your A2 Hosting account, you set up a virtual environment for Python, and then install and configure the s3cmd package.
Before you do this, however, you must log in to the AWS console and create a user group and a user. When you do this, AWS generates the user's Access key and Secret key. You must provide both of these keys during the s3cmd package configuration process.
The s3cmd Python package enables you to access and manipulate files that are in an Amazon S3 storage bucket by using the command line.
To install and configure the s3cmd package, follow these steps:
cd ~ virtualenv amazon
To activate the virtual environment, type the following command:
To install the s3cmd package and its dependencies, type the following commands:
pip install s3cmd python-magic
To make the s3cmd program executable, type the following command:
chmod +x ~/amazon/bin/s3cmd
To configure the s3cmd package for access to your Amazon S3 account, type the following command:
At the Test access with supplied credentials? prompt, type Y and then press Enter. If s3cmd is configured correctly, you receive the following message:
Success. Your access key and secret key worked fine : )
At the Save settings? prompt, type Y and then press Enter.
After you install and configure the s3cmd package and have verified that s3cmd can connect to Amazon S3, you are ready to create an Amazon S3 storage bucket, and a cron job to do the actual backup. To do this, follow these steps:
Type the following commands to create an Amazon S3 storage bucket. Replace bucket with the name of the bucket that you want to create:
cd ~ s3cmd mb s3://bucket
Bucket names must be unique. If you try to create a bucket with a name that is already in use (either by you or by someone else), you receive the following error message:
ERROR: Bucket 'bucketname' already exists
If this occurs, run the s3cmd mb command with a different bucket name until the command succeeds.
To verify that the bucket was created successfully, type the following command:
You should see a date/time stamp and the name of the bucket. For example:
2014-05-02 17:48 s3://bucketname
After you verify that the Amazon S3 bucket was created successfully, you are ready to set up a cron job that backs up files to the bucket automatically. To do this, the cron command must activate the virtual environment and then run the s3cmd program.
For example, the following command demonstrates how to back up the entire public_html directory to an S3 bucket daily at 2:30 AM. You should replace username with your own A2 Hosting account username, and bucket with the name of your own bucket:
30 2 * * * source /home/username/amazon/bin/activate ; s3cmd put --preserve --recursive /home/username/public_html s3://bucket
To restore data from an Amazon S3 bucket to your A2 Hosting account, follow these steps:
Type the following command to restore data. Replace bucket with the name of your bucket, path with the path to the files in the bucket that you want to transfer, and destination with the destination directory on your A2 Hosting account:
s3cmd get --recursive s3://bucket/path destination
You can also use the sync option to transfer files from the bucket to your A2 Hosting account. For more information about the sync option, type the following command at the command prompt: