12 Linux Rsync Options in Linux Explained |
In this article, I would show the different rync options to sync file/directories to the destination server. The main advantages of the rsync are: Speed: Initially copies the whole content between local and remote system. Next, it transfers only the changed blocks or bytes to the destination. Security: Encrypted form of data that can be transferred using ssh protocol. Less Bandwidth: rsync uses compression and decompression of the data block by block at both the ends. Syntax:
1) Rsync Over SSH and PortWith rsync, we can use SSH (Secure Shell) for data transfer, using SSH protocol while transferring our data you can be ensured that your data is being transferred in a secured connection with encryption so that nobody can read your data while it is being transferred over the wire on the internet. Also when we use rsync we need to provide the user/root password to accomplish that particular task, so using SSH option will send your logins in an encrypted manner so that your password will be safe. a) Copy a File from a Remote Server to a Local Server with SSHTo specify a protocol with rsync you need to give “-e” option with protocol name you want to use. Here in this example, We will be using “ssh” with “-e” option and perform data transfer.
b) Copy a File from a Local Server to a Remote Server with SSH
2) Show Progress While Transferring Data with rsyncTo show the progress while transferring the data from one machine to a different machine, we can use ‘–progress’ option for it. It displays the files and the time remaining to complete the transfer.
3) Use of –include and –exclude Options with rsyncThese two options allows us to include and exclude files by specifying parameters with these option helps us to specify those files or directories which you want to include in your sync and exclude files and folders with you don’t want to be transferred. Here in this example, rsync command will include those files and directory only which starts with ‘R’ and exclude all other files and directory.
4) Set the Max Size of Files to be TransferredYou can specify the Max file size to be transferred or sync. You can do it with “–max-size” option. Here in this example, Max file size is 200k, so this command will transfer only those files which are equal or smaller than 200k [cgi@server02:km]$ rsync -avhz -e "ssh -p 922 " --max-size='200k' /home/cgi/km/POLP4 cgi@192.27.128.188:/home/cgi/km/MONITORING/ 5) Automatically Delete source Files after successful TransferNow, suppose you have a main web server and a data backup server, you created a daily backup and synced it with your backup server, now you don’t want to keep that local copy of backup in your web server. So, will you wait for the transfer to complete and then delete that local backup file manually? Of Course NO. This automatic deletion can be done using ‘–remove-source-files‘ option.
6) Set Bandwidth Limit and Transfer FileYou can set the bandwidth limit while transferring data from one machine to another machine with the help of ‘–bwlimit‘ option. This options helps us to limit I/O bandwidth.
7) Enable CompressionIn the below command, rsysnc uses –z to enable compression, -v to verbose and -r to recursive. Here the command synchronizes two directories /home/aloft/ and /backuphomedir in the local system. [root@localhost /]# rsync -zvr /home/aloft/ /backuphomedir 8) Preserve File/Directory AttributesHere we have used –a option to preserve owner and groups, timestamp, symbolic links, permission and recursive mode. [root@localhost /]# rsync -azvr /home/aloft/ /backuphomedir 9) Synchronize local to remote hostBelow option allows you to synchronize between local machines to the remote machine. You can see while synchronizing files to another system, it asks for password. While doing synchronization with the remote server, you need to specify user name and IP or Hostname of the remote system.
10) Synchronize remote to local hostThe below options will synchronizes files from remote to local system. [root@localhost /]# rsync -avz azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/ /home/aloft/ 11) Find the difference in filesOption -avzi helps to find any differences in the files or directories between source and destination. [root@localhost backuphomedir]# rsync -avzi /backuphomedir /home/aloft/ 12) To Take backuprsync command could be used take linux backup. You can schedule backup in cron using rsync command,
Read Also: |
Posted - Wed, Oct 31, 2018 11:19 AM. This article has been viewed 11551 times. |
Online URL: http://kb.ictbanking.net/article.php?id=435 |
Powered by PHPKB (Knowledge Base Software)