Created
April 4, 2018 18:21
-
-
Save Scarsz/8af1da9428e2115543754ab77571e858 to your computer and use it in GitHub Desktop.
Script to backup specified directories to a compressed .tar.gz and upload to AWS S3
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 | |
bucket="milkyway-backups" | |
server="MILKYWAY" | |
subject="FILES" | |
locationstocompress=( "/home" "/var/www" "/etc/apache2" ) | |
masterfile="$server-$subject-$(date +"%Y-%m-%d").tar.gz" | |
tmpdir="/tmp/backup-$(echo $RANDOM % 999999 + 1 | bc)" | |
masterfile="/tmp/$masterfile" | |
mkdir "$tmpdir" | |
for location in "${locationstocompress[@]}"; do | |
echo "Compressing $location" | |
locationfile="$tmpdir/$(echo "$location" | tr / - | cut -c 2-).tar.gz" | |
tar -cI pigz -f "$locationfile" -C "$location" . | |
done | |
echo "Compressing to master file $masterfile" | |
tar -cI pigz -f "$masterfile" -C "$tmpdir" . | |
rm -r "$tmpdir" | |
echo "Uploading to S3" | |
aws s3 cp "$masterfile" "s3://$bucket/$server/$subject/" --storage-class STANDARD_IA | |
echo "Deleting master file" | |
rm "$masterfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment