5 most common Rsync command usage examples

rsync is a command for remote sync.

It is used to synchronise one location to another in a simple way. Location is meant to be local directory, server or remote web server or whatever accessible by ssh.

Advantages of using rsync over other tools is speed and bandwidth requirements. First time rsync copies entire contents of the directory provided and increments changes over next sync times.

Command syntax:

$ rsync options source destination

1. Synchronising local directories:

$ rsync -zvr /tmp/logs/ /tmp/logs1/
building file list ... done
created directory /tmp/logs1
./
log.log

sent 98 bytes  received 48 bytes  292.00 bytes/sec
total size is 0  speedup is 0.00
$
Used rsync command options here:

  • -z is for compression
  • -v is for verbose output
  • -r is for recursive directory scanning
By default rsync does not preserve timestamps. 

2. Preserve timestamps and permissions during sync:


$ rsync -azvr /tmp/logs/ /tmp/logs1/
building file list ... done
./
log.log

sent 122 bytes  received 48 bytes  340.00 bytes/sec
total size is 0  speedup is 0.00
$
Option -a preserves symbolic links, timestamps, user permissions and ownership.

3. Synchronize from Local to Remote:

$ rsync -avz /tmp/logs/ root@192.168.1.105:/home/user/logs/
root@192.168.1.105's password: 
building file list ... done
created directory /home/user/logs
./
log.log

sent 122 bytes  received 48 bytes  68.00 bytes/sec
total size is 0  speedup is 0.00
$
It is required to specify username and ip-address of the remote server, while doing synchronization. It is also required to specify the destination directory on the remote server. The format is username@machinename:path. Sometimes depending on your credentials and ssh authentication method you may need to enter a password. Like in this example.

4. Synchronize from Remote to Local:

$ rsync -avz root@192.168.1.105:/tmp/ ~/temp/
root@192.168.1.105's password: 
receiving file list ... done
./
#sql8ac_57e_182.MYD
#sql8ac_57e_182.MYI
#sql8ac_57e_182.frm
#sql8ac_57e_183.MYD
#sql8ac_57e_183.MYI
#sql8ac_57e_183.frm
#sql8ac_58f_b6.MYD
#sql8ac_58f_b6.MYI
#sql8ac_58f_b6.frm
#sql8ac_58f_b7.MYD
#sql8ac_58f_b7.MYI
#sql8ac_58f_b7.frm

sent 290 bytes  received 11002 bytes  3226.29 bytes/sec
total size is 16956702  speedup is 1501.66
$
This example is opposite to previous. we have synchronized a list of only changed files here. So speedup is relatively high.
5. View the rsync Progress during Transfer:
$ rsync -avz --progress root@192.168.1.105:/tmp/ ~/temp/
root@192.168.1.105's password: 
receiving file list ... 
284 files to consider
./
#sql8ac_57e_1ae.MYD
        1372 100%    1.31MB/s    0:00:00 (xfer#1, to-check=252/284)
#sql8ac_57e_1ae.MYI
        1024 100% 1000.00kB/s    0:00:00 (xfer#2, to-check=251/284)
#sql8ac_57e_1ae.frm
        8658 100%    8.26MB/s    0:00:00 (xfer#3, to-check=250/284)
#sql8ac_57e_1af.MYD
           0 100%    0.00kB/s    0:00:00 (xfer#4, to-check=249/284)
#sql8ac_57e_1af.MYI
        1024 100%  500.00kB/s    0:00:00 (xfer#5, to-check=248/284)
#sql8ac_57e_1af.frm
        8632 100%    2.74MB/s    0:00:00 (xfer#6, to-check=247/284)

sent 158 bytes  received 9666 bytes  3929.60 bytes/sec
total size is 16956814  speedup is 1726.06
$
Running with --progress option showcase detailed progress of server interaction during load operations.

Thats it. Hope you find this article helpful to you. Comments? Suggestions?

Comments

Popular posts from this blog

Django: Resetting Passwords (with internal tools)

Time Capsule for $25

Vagrant error: * Unknown configuration section 'hostmanager'.