Last active
March 16, 2017 23:03
-
-
Save asvnpr/9a28a84e593a2916c9c5ff6736304043 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
#! /usr/bin/env bash | |
# ask user for what to back up | |
read -p "Please enter the directory or file you wish to backup: " src | |
# compress and package | |
tar -czvf "$src-backup.tar.gz" "$src" | |
bak="$src-backup.tar.gz" | |
# ask where we're storing our backup | |
read -p "Enter directory or server where you want to store your backup: " dst | |
# check for remote destination | |
if echo "$dst" | grep -qe "(.*@.*\..*)" | grep -qe "^:$"; then dst+=':'; fi | |
# hash our backup | |
check=$(shasum -a 512 $src | cut -d ' ' -f 1) | |
# log our hash | |
echo "$src sha512 on `date +"on %d/%m/%Y at %H:%M:%S"`: $check" >> .backup.log | |
# backup | |
rsync -ve ssh --progress $bak $dst 2>>.backup.log | |
# error check | |
if [ $? -ne 0]; then | |
echo -e "\nThere was an error.\nCheck `pwd`.backup.log" | |
else | |
echo "\nBackup completed successfully" | |
rm "$bak" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment