Skip to content

Instantly share code, notes, and snippets.

@jksdua
Created March 8, 2015 06:09
Show Gist options
  • Save jksdua/8bf343dceaf2d82c884f to your computer and use it in GitHub Desktop.
Save jksdua/8bf343dceaf2d82c884f to your computer and use it in GitHub Desktop.
Hostgator shared hosting backup to AWS S3

Backup strategy

Hostgator shared hosting backup to AWS S3

Step 1

Install s3cmd command line tool.

  1. Copy s3cmd-setup.sh to the home folder via scp.
  2. sh ./s3cmd-setup.sh

Step 2

Copy fullbackup.sh and storebackup.sh to the home folder via scp.

Step 3

Setup cron jobs:

  1. sh <full_path_to_fullbackup.sh> "<user>" "<pass>" "<email>" "<cpanel_url/prefix>"
  2. sh <full_path_to_storebackup.sh> "s3_bucket/prefix"
#!/bin/sh
# Create a full cpanel backup
# - setup as cron job in the cpanel interface
# usage: sh ./fullbackup.sh <user> <pass> <email> <url_prefix>
curl -u "$1:$2" --data "dest=homedir&email=$3&email_radio=1" $4/frontend/x3/backup/dofullbackup.html | grep "in Progress"
#!/bin/sh
# Setup s3cmd tool for remote backups
# - source: http://kb.site5.com/shell-access-ssh/how-to-setup-and-configure-the-s3cmd-tool-for-amazon-s3/
# usage: sh ./s3cmd-setup.sh
# clone latest version of s3cmd
git clone https://github.com/s3tools/s3cmd.git
cd s3cmd
# install locally
python setup.py install --user
mkdir -p ~/bin
cp s3cmd ~/bin
cp -R S3 ~/bin
# remove s3 source
cd ../
rm -r s3cmd
# configure s3cmd
s3cmd --configure
#!/bin/sh
# Transfer backup to S3
# - uses s3cmd binary (install by cloning repo and `python setup.py --install --user`)
# - setup as cron job in the cpanel interface (a few minutes or hours after `fullbackup.sh` depending on backup size)
# usage: sh ./storebackup.sh <s3_bucket/prefix>
backup=$(find ~/ -name "backup-*.tar.gz")
/home1/jksdua/bin/s3cmd put $backup $1 && rm $backup
@basemwahba
Copy link

Thanks so much for this great backup strategy especially being run on a popular shared hosting account (hostgator). I fed up trying to apply similar method before on my hostgator shared hosting account, but I failed.
Thanks again for this.

How can we change the backup destination to be a folder we want instead of "homedir"?

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment