Thursday, August 14, 2014

rsync

Check http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/ for more details about rsync.
 Basic syntax of rsync command
$ rsync options source destination
Some common options used with rsync commands
  1. -v : verbose
  2. -r : copies data recursively (but don’t preserve timestamps and permission while transferring data
  3. -a : archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps
  4. -z : compress file data
  5. -h : human-readable, output numbers in a human-readable format

1. Copy/Sync Files and Directory Locally

$ rsync -zvh backup.tar /tmp/backups/ 
 
 

2. Copy/Sync Files and Directory to or From a Server

Send file to remote server 
$ rsync -avz rpmpkgs/ root@1.2.3.4:/home/
 
Get file from remote server 
$ rsync -avzh root@1.2.3.4:/home/tarunika/rpmpkgs  /tmp/myrpms 

3. Rsync Over SSH

To specify a protocol with rsync you need to give “-e” option with protocol name you want to use. Here in this example, We will be using “ssh” with “-e” option and perform data transfer.
$ rsync -avzhe ssh  root@192.168.0.100:/root/install.log   /tmp/
 

4. Show Progress While Transferring Data with rsync

To show the progress while transferring the data from one machine to a different machine, we can use ‘–progress’ option for it. It displays the files and the time remaining to complete the transfer.

$ rsync   -avzhe    ssh    --progress   /home/rpmpkgs    root@1.2.3.4:/root/rpmpkgs 

5. Use of –include and –exclude Options

These two options allows us to include and exclude files by specifying parameters with these option helps us to specify those files or directories which you want to include in your sync and exclude files and folders with you don’t want to be transferred.
Here in this example, rsync command will include those files and directory only which starts with ‘R’ and exclude all other files and directory.
$ rsync -avzh --include R*  root@1.2.3.4:/var/lib/rpm/ 

6. Use of –delete Option

If a file or directory not exist at the source, but already exists at the destination, you might want to delete that existing file/directory at the target while syncing .
We can use ‘–delete‘ option to delete files that are not there in source directory.
Source and target are in sync. Now creating new file test.txt at the target.
$ rsync    -avzh   --delete     root@1.2.3.4:/var/lib/rpm/       .

 

 

 

No comments:

Post a Comment