Skip to content

Instantly share code, notes, and snippets.

@markcaudill
Created August 17, 2013 15:00
Show Gist options
  • Save markcaudill/6257302 to your computer and use it in GitHub Desktop.
Save markcaudill/6257302 to your computer and use it in GitHub Desktop.
#!/bin/bash
tmpdir=$(mktemp -d)
s3bucket="s3://MY_BUCKET"
backup="$(date '+%Y-%m-%d-%H%M').tbz"
orig_pwd=$(pwd)
cd $HOME/..
logger -s -i "Backing up $HOME to $s3bucket/$(hostname -s)/$backup"
# Compress
tar -cjf $tmpdir/$backup $HOME
# Upload
s3cmd -e put $tmpdir/$backup $s3bucket/$(hostname -s)/
# Cleanup
rm -rf $tmpdir
cd $orig_pwd
# Delete all but the last 7 backups.
s3cmd ls $s3bucket/$(hostname -s)/ | awk '{print $4}' | head --lines=-7 | xargs s3cmd del
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment