Friday, August 26, 2016

Data Migration/Copy/Backup Using rsync command in Linux

rsync - stands for remote sync

rsync is used to perform the backup operation/data Migration in UNIX / Linux.
rsync utility is used to synchronize the files and directories from one location to another in an effective way. Backup location could be on local server or on remote server

Syntax

$ rsync options source destination
Source and destination could be either local or remote. In case of remote, specify the login name, remote server name and location.
options:
  • -z is to enable compression
  • -a = archive ( it preserves permissions (owners, groups), times, symbolic links, and devices  =  -rlptgoD)
  • -v verbose     ( it shows on the screen what is being copied )
  • -r indicates recursive ( it copies directories and sub directories)
  • -e rsync will use ssh
Examples:

Synchronize Two Directories in a Local Server

$ rsync -zvr /tmp/source_dir/ /destination_dir

Preserve timestamps during Sync using rsync -a

$ rsync -azv /tmp/source_dir/ /destination_dir/

Synchronize Files From Local to Remote

rsync -avz /tmp/source_dir/ user@192.168.1.1:/tmp/destination_dir/
Password:

Synchronize Files From Remote to Local

rsync -avz user@192.168.1.1:/tmp/remote_source_dir/ /tmp/local_destination_dir/
Password:

rsync using ssh

rsync -avz -e ssh user@192.168.1.1:/tmp/remote_source_dir/ /tmp/local_destination_dir/
Password:

View the Progress during rsync Transfer

rsync -avz --progress user@192.168.1.1:/tmp/remote_source_dir/ /tmp/local_dest_dir/
Password:

Specify --max-size of file for rsync Transfer (>100K will not be transfer)

rsync -avz --max-size='100K' user@192.168.1.1:/tmp/remote_srce_dir/ /tmp/local_dest_dir/
Password:

Transfer the Whole File with rsync -W

normally rsync transfers only the changed block to the destination, instead of sending the whole file, with the option -W it transfer the whole file

rsync -avzW user@192.168.1.1:/tmp/remote_srce_dir/ /tmp/local_dest_dir/
Password:

No comments:

Post a Comment