Home –  rsync command
Tag Archives: rsync command

Backup your Linux remotely using rsync command

rsync is a command in Linux which stands for remote sync. It is used for backing up the data. It synchronizes the directories and files from one location to another in a good way. The backup destination could be either on local or on remote server.

Features

  • Speed: rsync replicates all the data from source to destination and then it transfers only the changed blocks/bytes to the destination. This makes the transfer fast.
  • Security: It uses encryption using ssh technique.
  • Bandwidth: It compresses the block at source and then at the receiving end it decompresses the block. It transfers the data block by block using compression and decompression at source and destination side respectively. Hence uses less bandwidth.
  • Privileges: No extra privileges are required to use rsync.

Syntax

$ rsync options source destination

Case 1: Synchronize two directories in local server

use rsync -zvr command (z to enable compression, v for verbose, r for recursive)

$ rsync -zvr /var/opt/installation/inventory/ /root/temp

The above command does not preserves the timestamp.

Case 2: Preserve timestamps using rsync -a

The -a options preserves symbolic links, permissions, timestamp, owner and group.

$ rsync -azv /var/opt/installation/inventory/ /root/temp/

Case 3: Synchronize only a single file

Specify the file name to the rsync command

$ rsync -v /var/lib/rpm/Pubkeys /root/temp/

Case 4: Synchronize files Local->Remote

$ rsync -avz /root/temp/ chankey@192.168.200.10:/home/chankey/temp/

Case 5: Synchronize files Remote->Local

$ rsync -avz chankey@192.168.200.10:/var/lib/rpm /root/temp

Case 6: Select remote shell

$ rsync -avz -e ssh chankey@192.168.200.10:/var/lib/rpm /root/temp

rsync -e ssh => uses the ssh shell for remote sync

Case 7: Do not overwrite modified file at destination

If the file at the destination is modified and if we don’t want to change it back to the old one again then using rsync -u option.

$ rsync -avzu chankey@192.168.200.10:/var/lib/rpm /root/temp

Case 8: Synchronize only the directory Tree structure (not files)

use rsync -d option for this purpose.

$ rsync -v -d chankey@192.168.200.10:/var/lib/ .

Case 9: Do not create new file at destination, just update existing files

use --existing option

$ rsync -avz --existing root@192.168.1.2:/var/lib/rpm/ .

Case 10: Transfer the entire file

use rsync -W option

#  rsync -avzW  chankey@192.168.200.10:/var/lib/rpm/ /root/temp