The --exclude-from flag specifies a file that contains exclude patterns (one per line). The rsync man page is VERY detailed on the subject of filters and how they can be used.
Looking at a simplified version of my scenario, consider the following directory structure:
Source
|---.DS_Store
|---Alpha
| |---.DS_Store
| |---Document 1.txt
| |---Document 2.txt
| `---Temporary Items
| |---.DS_Store
| |---TI1.tmp
| `---TI2.tmp
|---Beta
| |---.DS_Store
| |---Document 3.txt
| |---Document 4.txt
| `---Temporary Items
| |---.DS_Store
| |---TI2.tmp
| `---TI4.tmp
`---Temporary Items
|---.DS_Store
`---TI5.tmp
I want backup the Source directory shown above and exclude the following from my backup:- All of the ".DS_Store" files.
- All of the "Temporary Items" directories.
- All files contained in the "Temporary Items" directories.
Destination
|---Alpha
| |---Document 1.txt
| `---Document 2.txt
`---Beta
|---Document 3.txt
`---Document 4.txt
Making this happen is very simple. The exclusions file (skip.txt) only needs to contain the following two lines:
Temporary Items .DS_StoreThe rsync command to perform the backup is as follows:
rsync -az --exclude-from=./skip.txt ./Source/ ./Destination/The output of this command is the "Destination" directory shown above.
There were two things that caused me greif getting my script to work:
- To exclude a file (or directory) with spaces in the name, the names DO NOT need to be quoted or escaped.
- To exclude all files underneath a directory you need only exclude the directory itself.
1 comments:
I was trying to scape white spaces all the time with no luck at all. Saved my life, thanks :)
Post a Comment