Rsync is a very good tool for synchronizing data between servers. It is better than ftp or other transmission software and is fast and stable, today I will introduce the rsync synchronization configuration to exclude files that we don't want to synchronize and not synchronize them.
Assume that the initial command is as follows:
Rsync-e 'ssh-p 30000 '-avl -- delete -- stats -- progress demo@123.45.67.890:/home/demo/backup/
I. exclude separate folders and files
To exclude the sources folder, we can add the '-- exclude' option:
-- Exclude 'Sources'
The command is as follows:
Rsync-e 'ssh-p 30000 '-avl -- delete -- stats -- progress -- exclude 'Sources' demo@123.45.67.890:/home/demo/backup/
To exclude the "database.txt" file in the "public_html" folder:
-- Exclude 'public _ html/database.txt'
The command is as follows:
Rsync-e 'ssh-p 30000 '-avl -- delete -- stats -- progress -- exclude 'Sources' -- exclude 'public _ html/database.txt 'demo@123.45.67.890:/home/demo/backup/
Ii. Use '-- exclude-from' to exclude Multiple folders and files
Create a file:
/Home/backup/exclude.txt
Define the folders and files to be excluded
Sources
Public_html/database .*
Downloads/test /*
Instructions:
-- Exclude-from '/home/backup/exclude.txt'
The final command is as follows:
Rsync-e 'ssh-p 30000 '-avl -- delete -- stats -- progress -- exclude-from'/home/backup/exclude.txt 'demo@123.45.67.890:/home/demo/backup/
Other common parameters of Rsync
1
-Z-compress file data during the transfer
-- Compress-level = NUM explicitly set compression level
-- Skip-compress = LIST skip compressing files with suffix in LIST
For compressed transmission, if the network bandwidth is not enough, it should be compressed for later transmission, which consumes Of course machine resources. However, if the number of files transmitted over the Intranet is not large, this parameter is unnecessary.
2
-- Password-file = FILE
As mentioned above, this parameter can be used only when the remote machine is an rsync server.
If you think that the FILE is written with the ssh login password, it is a big mistake. Many people have made this mistake.
3
-Stats: Adds a little more output regarding the file transfer status.
4
-Progress: shows the progress of each file transfer. Can be useful to know if you have large files being backup up.