Skip to main content

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

Pretty git Log

SO you dislike git log output in console like me and do not use it... Because it looks like so: How about this one? It's quite easy... Just type: git log - - graph - - pretty = format : '%Cred%h%Creset -%C ( yellow ) %d%Creset %s %Cgreen ( %cr) %C ( bold blue ) <%an>%Creset' - - abbrev - commit - - It may be hard to enter such an easy command every time. Let's make an alias instead... Copypaste this to your terminal: git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --" And use simple command to see this pretty log instead: git lg Now in case you want to see lines that changed use: git lg - p In order for this command to work remove  the -- from the end of the alias. May the code be with you! NOTE: this article is a rewritten copy of  http://coderwall.com/p/euwpig?i=3&p=1&t=git   and have b...

Django: Resetting Passwords (with internal tools)

I have had a task recently. It was about adding a forms/mechanism for resetting a password in our Django based project. We have had our own registration system ongoing... It's a corporate sector project. So you can not go and register yourself. Admins (probably via LDAP sync) will register your email/login in system. So you have to go there and only set yourself a password. For security reasons you can not register. One word. First I've tried to find standart decision. From reviewed by me were: django-registration and django password-reset . These are nice tools to install and give it a go. But I've needed a more complex decision. And the idea was that own bicycle is always better. So I've thought of django admin and that it has all the things you need to do this yourself in no time. (Actually it's django.contrib.auth part of django, but used out of the box in Admin UI) You can find views you need for this in there. they are: password_reset password_reset_...

Vagrant error: * Unknown configuration section 'hostmanager'.

Sometimes you get a vagrant environment or boilerplate with a Vagrantfile config in there and do a vagrant up command. And see some errors. like this: There are errors in the configuration of this machine . Please fix the following errors and try again : Vagrant: * Unknown configuration section 'hostmanager'. To fix this one needs: $ vagrant plugin install vagrant - hostmanager Installing the ' vagrant-hostmanager ' plugin . This can take a few minutes . . . Fetching : vagrant - hostmanager - 1.8 .6 . gem ( 100 % ) Installed the plugin ' vagrant-hostmanager (1.8.6) ' ! So command to fix this as follows: vagrant plugin install vagrant-hostmanager