Skip to content

Using Amazon S3 to Back Up and Restore Data in Ruachost

Ruachost allows you to configure Amazon S3 as an offsite backup destination for your hosting account. This ensures your website files and databases are securely stored in the cloud and can be restored if needed.

  • Offsite protection: Keeps your data safe even if your hosting server is compromised.
  • Scalability: Store large amounts of data without worrying about local disk limits.
  • Automation: Schedule backups to run automatically via cron jobs.
  • Reliability: Benefit from Amazon’s highly available cloud infrastructure.

Before you begin, you’ll need:

  • An Amazon Web Services (AWS) account.
  • An IAM user with programmatic access enabled.
  • The user’s Access Key and Secret Key.
  • An S3 bucket created in your AWS account.

s3cmd is a command-line tool that allows you to interact with Amazon S3.

  1. Log in to your Ruachost account via SSH.

  2. Create a Python virtual environment:

    Terminal window
    cd ~
    virtualenv amazon
    source ~/amazon/bin/activate
  3. Install s3cmd:

    Terminal window
    pip install s3cmd python-magic
  4. Make it executable:

    Terminal window
    chmod +x ~/amazon/bin/s3cmd
  5. Configure s3cmd:

    Terminal window
    s3cmd --configure
    • Enter your Access Key and Secret Key.
    • Accept defaults for encryption and GPG.
    • Choose Yes for HTTPS.
    • Test credentials, you should see a Success message.
  1. Ensure your virtual environment is active:

    Terminal window
    source ~/amazon/bin/activate
  2. Create a new bucket (replace bucketname with your own):

    Terminal window
    s3cmd mb s3://bucketname
  3. Verify the bucket:

    Terminal window
    s3cmd ls
  4. Set up a cron job to back up your site daily at 2:30 AM:

    Terminal window
    30 2 * * * source /home/username/amazon/bin/activate; s3cmd sync --preserve --recursive /home/username/public_html s3://bucketname
    \
    Replace username with your Ruachost account username.
    • Use sync instead of put for efficiency (only new/changed files are uploaded).
  1. Activate your virtual environment:

    Terminal window
    source ~/amazon/bin/activate
  2. Restore files from your bucket:

    Terminal window
    s3cmd get --recursive s3://bucketname/path /home/username/restore/
    • Replace path with the folder or file path in S3.
    • Replace /home/username/restore/ with your desired destination.