Skip to content

Instantly share code, notes, and snippets.

@jaydrogers
Created April 3, 2014 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jaydrogers/9957551 to your computer and use it in GitHub Desktop.
Save jaydrogers/9957551 to your computer and use it in GitHub Desktop.
CRON Job that will execute moving backup files to Amazon S3. Usage info here: http://serversideup.netmedia-temple-amazon-s3-backup-and-other-linux-servers
#! /bin/bash
# Author: Jay Rogers - jay@521dimensions.com
#IMPORTANT -- CONFIGURATION VARIABLES
BACKUPDOMAIN=backup.mydomain.com
SITESBUCKETNAME=myserver-plesksites
SERVERBUCKETNAME=myserver-pleskfull
#Check to see if there are any individual SITES to back up. If so, move the backups to Amazon S3
if [ "$(find /var/www/vhosts/$BACKUPDOMAIN/s3backups/sites/ -name "*.tar")" ]; then
#Make sure that CRON is able to find the AWS Configuration File
export AWS_CONFIG_FILE=/root/.aws/config
#Execute S3 moved to Bucket configured above
aws s3 mv /var/www/vhosts/$BACKUPDOMAIN/s3backups/sites/ s3://$SITESBUCKETNAME --recursive
fi
#Check to see if there are any SERVER backups to move. If so, move the backups to Amazon S3
if [ "$(find /var/www/vhosts/$BACKUPDOMAIN/s3backups/fullserver/ -name "*.tar")" ]; then
#Make sure that CRON is able to find the AWS Configuration File
export AWS_CONFIG_FILE=/root/.aws/config
#Execute S3 moved to Bucket configured above
aws s3 mv /var/www/vhosts/$BACKUPDOMAIN/s3backups/fullserver/ s3://$SERVERBUCKETNAME --recursive
exit 0
else
#If nothing exists in any of these folders, then do nothing
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment