Using rsync

From vpsget wiki
Jump to: navigation, search
  • Rsync Example Commands

If you need to copy some data from one server to another you can use scp. But if you would like to sync data you can use more powerful tool called rsync. The detailed differ of rsync and scp you can find in the internet but the main one that you can resume stopped /killed process and continue synchronize data.

We will share the example of the usage: Semantic:

rsync -avzH --numeric-ids -e 'ssh -p<ssh_port>' /local/path/somefile.tar.gz <destination_IP>:/remote/path/somefile.tar.gz

Example:

rsync -avzH --numeric-ids -e 'ssh -p6622' /vz/template/cache/centos-6-x86.tar.gz 192.168.1.2:/vz/template/cache/centos-6-x86.tar.gz


Example2 .

This command can be used to synchronize a folder, and also resume copying when it's aborted half way. The command to copy one mnt folder /disk is:

rsync -avxHAX --progress /mnt/some_disk /usr/bcp/

Note that some_disk folder will appear aunder bcp folder; [slashes means!]

Example3:

Rsync folder to remote server with preserving timestamps [for owncloud datadir move for e.g.] ( resume copying when it's aborted half way)

rsync -avxtHAX --progress -e 'ssh -p6622'  /mnt/source_folder root@192.168.1.2:/home/target_folder/

Example4: rsync exact folder on another server excluding some subfolders:

rsync -avxtHAX --progress -e 'ssh -p6622'  --exclude 'dir1'  --exclude 'dir2'  /mnt/some_folder/ root@192.168.1.2:/home/some_folder/

Or with a single --exclude option:

rsync -avxtHAX --progress -e 'ssh -p6622'  --exclude={'file1.txt','dir1/*','dir2'}   /mnt/some_folder/ root@192.168.1.2:/home/some_folder/

in this case the dir1 will be created but without syncing directory's content

Or put the excludes into exclude file:

rsync -avxtHAX --progress -e 'ssh -p6622'  --exclude-from='exclude-file.txt'   /mnt/some_folder/ root@192.168.1.2:/home/some_folder/

exclude-file.txt should contain exclude files /dirs line by line:

file1.txt
dir1/*
dir2


Command options clarification:

-a  : all files, with permissions, etc..
-v  : verbose, mention files
-x  : stay on one file system
-H  : preserve hard links (not included with -a)
-A  : preserve ACLs/permissions (not included with -a)
-X  : preserve extended attributes (not included with -a)
-t  : preserve modification times


Speedup Rsync: do not use compression -z and add --inplace option so it will not use tmp filesystems; also leave minimal params like -av only:

rsync -av  --progress  --inplace -e 'ssh -p8965' /vz/private/101 root@46.*.*.*:/archive_srv_ploop_bcp/