Skip to content

Instantly share code, notes, and snippets.

@abegodong
Created June 25, 2013 06:46
Show Gist options
  • Save abegodong/5856481 to your computer and use it in GitHub Desktop.
Save abegodong/5856481 to your computer and use it in GitHub Desktop.
S3 backup using s3cmd.
!/bin/sh
#####################
# Backup Management to S3
# 2013/06/19 - Abraham Godong
# Require s3cmd
KEEP_BACKUP=3
BUCKET=$1
SOURCE=$2
HOSTNAME=(`hostname -s`)
NOW=(`date +\%Y_\%m_\%d`)
PAST=(`date --date="-$KEEP_BACKUP days" +\%Y_\%m_\%d`)
echo "Uploading new Backup Files";
s3cmd put $SOURCE s3://$BUCKET/$HOSTNAME/$NOW/
echo "Deleting old Backup Files";
s3cmd del --recursive s3://$BUCKET/$HOSTNAME/$PAST/
echo "Deleting local Backup Files";
rm -rf $SOURCE
echo "DONE!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment