KISS

Keep It Simple Stupid

rsync: exclude rules quirks

| comments

rsync is a great tool for syncing, backing up, restoring directories with a lot of features. It comes with most Linux distributions and OS X. However, the exclude rules file has some quirks.

Suppose you want to backup all your the most crucial files (sources of the blogs, passwords databases, private documents, ssh/ssl keys, etc), scattered all around the filesystem. (It’s a good idea to backup your files!) So the basic command is:

1
rsync --archive --human-readable --verbose --recursive --delete-excluded --inplace --checksum --exclude-from=excludes.lst / my-backup/

The most interesting part for us now is --exclude-from=excludes.lst, which specifies what we actually want to copy. Its format can be looked up in the man page, we’ll check some examples.

Suppose you want get /etc/inputrc backed up, you need these lines:

1
2
3
4
5
6
# include the file
+ /etc/inputrc

# ignore everything else
+ /etc/
- /etc/*

If you need to backup a directory (/etc/X11/xorg.conf.d/) but not everything else, the idea is similar:

1
2
3
4
5
6
+ /etc/X11/xorg.conf.d/

+ /etc/
+ /etc/X11/
- /etc/X11/*
- /etc/*

And finally, one more step in hierarchy:

1
2
3
4
5
6
7
8
+ /usr/local/bin/noinet

+ /usr/
+ /usr/local/
+ /usr/local/bin/
- /usr/local/bin/*
- /usr/local/*
- /usr/*

Helpful link: http://www.linuxquestions.org/questions/linux-software-2/rsync-include-exclude-problems-636504/.

Comments