How to rsync all folders present on the destination folder
I have two folders FolderA and FolderB as below. I want to rsync the common subfolders. For example, I can do rsync -avzP /path/to/FolderB/* /path/to/FolderA/, which will keep SubFolder1 and SubFolder3 mirrored. My question is how I can achieve the same if FolderB is the destination without explicitly --include or --exclude individual subfolders (e.g., in case there are too many of them).
“` FolderA |—SubFolder1 |—SubFolder2 |—SubFolder3 |—SubFolder4
FolderB |—SubFolder1 |—SubFolder3 “**
Answer by David C. Rankin If you have a large number of folders under FolderA that you do not want to sync under FolderB, then your other option is to create a text file holding the absolute path to only those SubFolderX under FolderA you want to rsync to FolderB and then use the --no-R and --files-from=folderlist options to only rsync the wanted SubFolders. This will eliminate having to specify a large number of --filter options on the command line.
For example, you can create your folderlist with:
find /path/to/FolderA -maxdepth 1 -type d > folderlist
(note: specify the absolute path above and find will produce the folderlist file containing absolute paths)
Now edit your folderlist file and remove the parent directory (e.g. /path/to/FolderA) and any SubFolders you don’t want to sync under FolderB. You can now use the folderlist file to control which SubFolders under FolderA are sync’ed to FolderB without having to include a long list of filters on the command line. Your command line then becomes
rsync -uai -r --no-R --files-from=folderlist / /path/to/FolderB
(note: the '/' as source serves as a base for the paths contained in folderlist. You can change the -i option to control the level of information dumped to the screen, e.g. -v, etc… or remove it altogether to suppress any reporting other than errors)
(also note: when using --files-from, -a does not imply -r (recursive), so you will need to explicitly add -r if you need a recursive transfer)
Comments
Comments powered by Disqus