Skip to content

Instantly share code, notes, and snippets.

@bwmorales
Last active December 11, 2017 10:47
Show Gist options
  • Save bwmorales/7aa41d266c24c9eb12e9108ed3f287c2 to your computer and use it in GitHub Desktop.
Save bwmorales/7aa41d266c24c9eb12e9108ed3f287c2 to your computer and use it in GitHub Desktop.
(macOS) Rsync a file, check that backup was successful, and send a message to the printlog function
# Rsync a file, check that backup was successful, and send a message to the printlog function
# Printlog function is available at https://gist.github.com/bwmorales/86a1a8c4ec51c9e2ffba1499a2c211e0
# Example Usage:
# backup $HOME/Documents/myfile.txt
export TODAY=$(date +"%Y-%m-%d")
backup() {
if [[ -e "${1}" ]]; then
rsync -aE "${1}" "${1}.${TODAY}.bak"
if [[ -e "${1}.${TODAY}.bak" ]]; then
if [[ "$(shasum "${1}" | awk '{ print $1 }')" == "$(shasum "${1}.${TODAY}.bak" | awk '{ print $1 }')" ]]; then
printlog -g "Backup of '${1}' succeeded."
return 0
else
printlog -r "Backup of '${1}' failed."
return 1
fi
else
printlog -r "Backup of '${1}' failed."
return 1
fi
else
printlog -y "'${1}' does not exist. Skipping."
return 0
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment