If you have not already set up an Amazon Web Services (AWS) account, you must do so before following the procedures below. To set up an Amazon AWS account, please visit https://aws.amazon.com.
Using Amazon S3 at hosting.com
To access Amazon S3 services on your hosting.com 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.Installing and configuring the s3cmd package
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:- Log in to your account using SSH.
- To create the Python virtual environment, type the following commands at the command prompt:
- To activate the virtual environment, type the following command:
The command prompt changes to (amazon)username@example.com to indicate that you are running within a virtual environment.
- To install the s3cmd package and its dependencies, type the following command:
- To make the s3cmd program executable, type the following command:
- To configure the s3cmd package for access to your Amazon S3 account, type the following command:
- At the Access Key prompt, type the AWS user’s Access key and then press Enter.
- At the Secret Key prompt, type the AWS user’s Secret key and then press Enter.
- At the Encryption password prompt, press Enter.
- At the Path to GPG program prompt, press Enter.
-
At the Use HTTPS protocol prompt, type
Yesand then press Enter. -
At the Test access with supplied credentials? prompt, type
Yand then press Enter. If s3cmd is configured correctly, you receive the following message:
If you do not receive this message, s3cmd reviews the configuration settings. Make any necessary changes, and then try again.
- At the Save settings? prompt, type
Yand then press Enter.
Backing up data to Amazon S3
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:- At the command prompt, make sure that you are running within the virtual environment. If the command prompt does not begin with (amazon), type the following command to activate the virtual environment:
- Type the following commands to create an Amazon S3 storage bucket. Replace bucket with the name of the bucket that you want to create:
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: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:
- 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 entirepublic_html directory to an S3 bucket daily at 2:30 AM. You should replace username with your own hosting.com account username, and bucket with the name of your own bucket:
Restoring data from Amazon S3
To restore data from an Amazon S3 bucket to your hosting.com account, follow these steps:- At the command prompt, make sure that you are running within the virtual environment. If the command prompt does not begin with the name of your virtual environment in parentheses, type the following command to activate the virtual environment:
- 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 hosting.com account:
More information
- For general information about Amazon S3, please visit https://aws.amazon.com/s3.
- To view the official Amazon S3 documentation, please visit https://aws.amazon.com/documentation/s3.