So what is Rsync?
Rsync is a Linux tool which helps is syncing a file from a server A to server B and vice versa. Rsync is powerful tool which numerous options and we will see some of the examples below.
Rsync Command to copy files in the destination.
So the basic command would look like this.
[root@server ~]# rsync [option] user@host:[file/directory origin] [destination]
[root@server ~]# rsync -avzh /home/user/backups/ user@backup01:/home/backup/
So above command will copy contents in the backups folder to the remote destination – Important note if you don’t put trailing / in the /home/user/backups it will copy whole folder instead of just contents in it.
Further to explain above command:-
-a stands for copy files recursively and preserve ownership of files when files are copied
-v stands for runs the verbose version of the command; all of the processes that are run will be written out for the user to read
-z stands for compress the data synced
– h stands for produce easily readable output, not just numbers
If you are doing a large transfers and want to see progress, you can use –progress option.
[root@server ~]# rsync -avzh --progress /home/user/backups/ user@backup01:/home/backup/
Exclude Files/folders from syncing.
Create a file call exclude.txt and add all the files and folders you want to exclude e.g:-
rsync -avzh --exclude-from 'exclude.txt' sync/ 22.214.171.124:/home/