Announcement

Collapse
No announcement yet.

Rsync command in Linux

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rsync command in Linux

    As most of we believe rsync is the best tool that can be used to perform backups. It can be used to copy files on the local system or remotely through the network. The main difference between rsync and tar is that rsync only copies the differences between the source and destination, tar always copy all the data structure from the source when the tar is created and all the data is restored on destination.
    Code:
    $ rsync -av /usr/local/ /tmp/destination/
    
    sending incremental file list
    ...
    share/man/mann/
    share/perl5/
    src/
    sent 514 bytes received 45 bytes 1118.00 bytes/sec
    total size is 0 speedup is 0.00
    Copy recursively /usr/local/* on /tmp/destination/ directory, for example /usr/local/bin is copied on /tmp/destination/bin.
    Code:
    $ rsync -avz /usr/local/ root@remotehost:/tmp/destination/
    
    sending incremental file list
    ...
    share/man/mann/
    share/perl5/
    src/
    sent 514 bytes received 45 bytes 1118.00 bytes/sec
    total size is 0 speedup is 0.00
    Copy recursively /usr/local/* on /tmp/destination/ directory on remotehost using ssh or rsync credentials. In this case compression is enabled 'z' because the copy is done through the network.
    Code:
    $ rsync -avz --delete /usr/local/ root@remotehost:/tmp/destination/
    
    sending incremental file list
    ...
    share/man/mann/
    share/perl5/
    src/
    sent 514 bytes received 45 bytes 1118.00 bytes/sec
    total size is 0 speedup is 0.00
    Copy recursively /usr/local/* on /tmp/destination/ directory on remotehost. In this case it also deletes '--delete' the files that are on destination but not on source: it keeps on completely sync /usr/local/ and /tmp/destination/ on the remote host.

    Note : rsync keeps file permissions and ownership on the file transmission, but it does not keep selinux attributes. There is not such option as '--selinux' as tar, the selinux relabeling must be done by hand with the 'chcon' command.

    * In order to restore the information, just switch the source <-> destination :
    Code:
    $ rsync -n -av /tmp/destination/ /usr/local/
    sending incremental file list
    ./
    file1
    file2
    
    sent 567 bytes received 54 bytes 1242.00 bytes/sec
    total size is 0 speedup is 0.00 (DRY RUN)
    With the dry-run option '-n' the rsync is simulated but it is not done. This is a very useful option to test what is going to be copied or deleted by the rsync command just before running it.
    Code:
    $ rsync -av /tmp/destination/ /usr/local/
    
    sending incremental file list
    ./
    file1
    file2
    
    sent 639 bytes received 86 bytes 1450.00 bytes/sec
    total size is 0 speedup is 0.00
    The restore has been done
    Last edited by kuldeep; 02-22-2015, 01:06 AM.
Working...
X