Skip to content

Instantly share code, notes, and snippets.

@ngekoding
Created October 4, 2020 09:52
Show Gist options
  • Save ngekoding/ab6fdc1513e2f98df30288c00a923099 to your computer and use it in GitHub Desktop.
Save ngekoding/ab6fdc1513e2f98df30288c00a923099 to your computer and use it in GitHub Desktop.
rsync bash script to simplify the process (supporting .gitignore, etc...)
#!/bin/bash
helpFunction()
{
echo ""
echo "Usage: $0 -s source -d destination"
echo -e "\t-s Source folder"
echo -e "\t-d Destination folder"
echo ""
echo -e "Notes:\t- All files in .gitignore will be ignored"
echo -e "\t- All files in .rsyncignore will be ignored"
echo -e "\t- All files in .rsyncinclude will be included"
echo -e "\t Used for including the files which listed in .gitignore"
exit 1 # Exit script after printing help
}
while getopts "s:d:" opt
do
case "$opt" in
s ) source="$OPTARG" ;;
d ) destination="$OPTARG" ;;
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
esac
done
# Print helpFunction in case parameters are empty
if [ -z "$source" ] || [ -z "$destination" ]
then
echo "Some or all of the parameters are empty";
helpFunction
fi
# Begin script in case all parameters are correct
rsync -avz --delete --include-from="$source/.rsyncinclude" --filter=":- $source/.gitignore" --filter=":- $source/.rsyncignore" $source/ $destination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment