Created
February 3, 2018 15:03
-
-
Save lambrospetrou/3c678ae6d089a50aa809d328a58f875e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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