exclude multiple directories in rsync
Exclude multiple directories in rsync.
rsync It is commonly found on Unix-like systems and functions as both a file synchronization and file transfer program. The rsync algorithm is a type of delta encoding, and is used for minimizing network usage. Rsync is typically used for synchronizing files and directories between two different systems.
If you want exclude unwanted files while rsync you can use –exclude ‘dir1.
Eg: if you want exclude a single directory
rsync -avz --exclude 'dir1' source/ destination/
Here I need to exclude group of directories, so I have created a file called /root/exclude.txt
vim /root/exclude.txt dir1 dir3 dir3 dir5
save the file.
I need to copy a some data to external server, so I already set a key-gen no need to mention the password. Here we need to use –exclude-from then mention your file name
rsync -avz --delete-before --exclude-from '/root/exclude.txt' /backup/* [email protected]:/backup/user1/
FYI : The above command used for syncing the contents from /backup to the remote storage location /backup/user1.
In the /root/exclude.txt file , I have excluded some directories that belongs to /backup (source server). So it will copy only remaining directories to the remote server back.hostname location /backup/user1/
Make sense ? any doubts let me know.