Skip to content

Instantly share code, notes, and snippets.

@xeor
Created October 30, 2015 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeor/027118572574d6196672 to your computer and use it in GitHub Desktop.
Save xeor/027118572574d6196672 to your computer and use it in GitHub Desktop.
rsync backup with rules fule
#!/bin/bash
RSYNC="/usr/bin/rsync"
mydir=$(cd $(dirname $0);pwd)
todir="/backup"
cat "${mydir}/rules" | grep ^[+-] | $RSYNC -v -azr -T "${mydir}/tmp" --include-from=- / server:${todir}
# To test, use "rsync -nvv -azr --include-from=include / /tmp/", will not copy anything
# Since we have "- *" at the end, we must include every folder to the folder we want to include..
# Rules are read (logically) by rsync from the bottom and up. So if we have - * at the end, we should include
# all the directories above it.. Put / at the end of directories!
# - will exclude
# + will include
# ** means include everything AND subfolders.. Eg, + /etc/**, we will still need + /etc/.
# # Is comments :)
+ /
+ /Pictures/
+ /Pictures/by_year/
+ /Pictures/by_year/**
- *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment