Excluding a folder from the home directory with rsync exclude list
Simply put, rsync
uses relative paths to determine what to exclude. From the rsync
manpage:
If the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files, otherwise it is matched against the end of the pathname. This is similar to a leading ^ in regular expressions. Thus "/foo" would match a file named "foo" at either the "root of the transfer" (for a global rule) (…)
The simplest way to work around this is to use --relative
/ -R
, which lets you exclude Dropbox like so:
rsync -avR --exclude='/Users/alex/Dropbox' /Users/alex /Volumes/Backup_Mac
The name relative
refers to how rsync
sends the paths and therefore doesn't have anything to do with specifying absolute exclude patterns.
Note that this creates the full directory tree /Volumes/Backup_Mac/Users/alex/
, but that's not a terribly bad thing in your case.
Related videos on Youtube
Alex
Updated on September 18, 2022Comments
-
Alex almost 2 years
I am trying to set up
rsync
for OS X 10.8.4 using an exclude file. However, it does not recognize the paths I want to exclude.I want to copy the user
ABC
's home directory to a folder calledBackup_Mac
on a mounted external drive.rsync -av --progress --exclude-from='/Users/ABC/excludelist.txt' /Users/ABC /Volumes/Backup_Mac
excludelist.txt
contains- /Users/ABC/Dropbox/
It is not excluding the Dropbox folder.
Now if I change the exclude file to
- Dropbox/
it is excluding
ABC/Dropbox
but also all other folders named Dropbox elsewhere in the file tree. This is not what I want – I want to exclude only the folderABC/Dropbox
but include any other folders calledDropbox
, e.g.ABC/Application Support/Dropbox
.Any hint on how to achieve that? How do I have to specify the exclude path, relative to the folder backed up, or relative to root?
-
slhck almost 11 yearsDoes your list literally contain a hyphen and a space before the path?
-
Alex almost 11 yearsIt does. I tried different variations (removing hyphen and/or space), none of them work.
-
-
Alex almost 11 yearsThat is the solution, indeed. Many thanks my friend. It also works using the 'exclude file', awesome!
-
flipdoubt over 8 yearsBonus Followup: Does one need to exclude the Volumes directory? I'm doing the following, but the progress messages look as though it is considering files within the Volumes directory:
rsync --archive --progress --verbose --inplace -- exclude '/Volumes' / /Volumes/NetBackup/iMacRsync/
-
slhck over 8 years@flipdoubt Since
/Volumes
is a direct child of the root, yes, you'd have to exclude it when you want to sync/
.