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

Time Capsule for $25

The real article name might be something like:  Configuring Raspbery Pi to serve like a Time Capsule with Netatalk 3.0 for Mountain Lion.  But it's too long ;) Here I will describe the process of using Raspberry Pi like a Time Machine in my network. To be able to backup your MAC's remotely (Like it would be NAS of some kind). It assumes you have a Raspberry Pi and have installed a Raspbian there and have a ssh connection, or somehow having access to it's console. Refer to my previous article for details . Now that we have a Pi that is ready for action let's animate it. So to make it suit you as a Time Capsule (NAS) for your MAC's you need to do those basic steps: - connect and configure USB hard drive(s) - install support of HFS+ filesystem to be able to use MAC's native filesystem - make mount (auto-mount on boot) of your hard drive - install Avahi and Netatalk demons - configure Netatalk daemon to make it all serve as a Time Machine - configure ...

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_...

Django: Beautiful multiple files Upload Plugin using jQuery UI.

After successful developing python back-end for Sebastian Tschan jQuey Plugin  I've decided to make a reusable app for that purpose. So: This is a plugin, made using multiupload form from Sebastian Tschan. It uses jQuey UI and jQuery instead of Flash uploader. On Django side it uses sorl-thumbnails and PIL. You can use it in your applications with simple inclusion tag jQuery Features it has: Multiple file upload: Allows to select multiple files at once and upload them simultaneously. Drag & Drop support: Allows to upload files by dragging them from your desktop or filemanager and dropping them on your browser window. Upload progress bar: Shows a progress bar indicating the upload progress for individual files and for all uploads combined. Cancelable uploads: Individual file uploads can be canceled to stop the upload progress. Resumable uploads: Aborted uploads can be resumed wi...