Skip to content

Instantly share code, notes, and snippets.

@Stmol
Last active December 17, 2015 04:28
Show Gist options
  • Save Stmol/5550621 to your computer and use it in GitHub Desktop.
Save Stmol/5550621 to your computer and use it in GitHub Desktop.
Simple backup through rsync
#!/bin/bash
DIST_DIR="/Volumes/Stmol HDD/Backup"
if [ ! -d "$DIST_DIR" ]; then
echo "-- Error: Directory $DIST_DIR not found"
exit
fi
echo "-- Start backuping to $DIST_DIR"
# Source directories
SRC_DIRS=(
"/Users/Stmol/Dropbox"
"/Users/Stmol/Documents"
"/Users/Stmol/Projects"
"/Users/Stmol/Pictures"
"/Users/Stmol/Music"
"/Users/Stmol/Movies"
)
# Excludes
EXCLUDE=(
".DS_Store"
"Icon"
"Projects/Git/"
)
# Concatenate exclude string
for ((j=0;j<${#EXCLUDE[@]};j++)); do
EXCLUDE_LINE="$EXCLUDE_LINE --exclude \"${EXCLUDE[${j}]}\""
done
# Command for execute
COMMAND="rsync -r --delete --size-only $EXCLUDE_LINE \"${SRC_DIRS[${i}]}\" \"$DIST_DIR\""
for ((i=0;i<${#SRC_DIRS[@]};i++)); do
echo "-- Backup dir: ${SRC_DIRS[${i}]}"
eval $COMMAND
echo "-- Done"
echo ""
done
echo "-- End"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment