Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambrospetrou/3c678ae6d089a50aa809d328a58f875e to your computer and use it in GitHub Desktop.
Save lambrospetrou/3c678ae6d089a50aa809d328a58f875e to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
SOURCE_DIR="the-dir-to-save"
S3_BUCKET="s3://your-s3-bucket/with/path"
TIMENOW="$(date --rfc-3339=seconds | tr ' ' '_' | tr ':' '-' | tr '+' '.')"
FILENAME="$SOURCE_DIR.$TIMENOW.tgz"
DEST_TAR="/tmp/$FILENAME"
# Assumes the SOURCE_DIR is in your $HOME
tar -cvzf "$DEST_TAR" -C "$HOME" "$SOURCE_DIR"
aws s3 cp "$DEST_TAR" "$S3_BUCKET$FILENAME" --storage-class STANDARD_IA --sse
# Schedule the above to run with cron periodically
# Once a day at 20:00
# crontab -e
# 0 20 * * * /home/username/path-to-the-script-above/./script.sh > /tmp/crontab.backup-source-dir.log 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment