Skip to content

Instantly share code, notes, and snippets.

@SunRed
Created March 23, 2021 15:03
Show Gist options
  • Save SunRed/5e4b8c14c80881912a234cda54411f9b to your computer and use it in GitHub Desktop.
Save SunRed/5e4b8c14c80881912a234cda54411f9b to your computer and use it in GitHub Desktop.
Simple script utilizing rsync to sync two directories.
#!/bin/bash
set -e
read -e -p "Source Directory [./]: " SOURCE
SOURCE=${SOURCE:-./}
read -e -p "Destination Directory [../Mirror]: " DEST
DEST=${DEST:-../Mirror}
if [ $# -eq 0 ] || [ -z $1 ]
then
rsync -ai --delete --exclude={"/.*","/mirror.sh"} "${SOURCE}" "${DEST}"
elif [ $# -eq 1 ] && [ "$1" = "--dry-run" ]
then
echo "*** DRY RUN ***"
rsync -ain --delete --exclude={"/.*","/mirror.sh"} "${SOURCE}" "${DEST}"
else
echo "Unknown argument(s): ${@}"
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment