Advertisement
chotoipho

BASH: rsync command

Feb 12th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. http://www.cyberciti.biz/tips/linux-use-rsync-transfer-mirror-files-directories.html
  2.  
  3. HowTo Use rsync For Transferring Files Under Linux or UNIX
  4.  
  5. by nixCraft on December 5, 2006 · 52 comments· Last updated August 8, 2012
  6.  
  7. How do you install and use rsync to synchronize files and directories from one location (or one server) to another location? - A common question asked by new sys admin.
  8.  
  9. rsync is a free software computer program for Unix and Linux like systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar programs/protocols is that the mirroring takes place with only one transmission in each direction.
  10. So what is unique about the rsync command?
  11.  
  12. It can perform differential uploads and downloads (synchronization) of files across the network, transferring only data that has changed. The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network connection.
  13. How do I install rsync?
  14.  
  15. Use any one of the following commands to install rsync. If you are using Debian or Ubuntu Linux, type the following command:
  16. # apt-get install rsync
  17. OR
  18. $ sudo apt-get install rsync
  19. If you are using Red Hat Enterprise Linux (RHEL) / CentOS 4.x or older version, type the following command:
  20. # up2date rsync
  21. RHEL / CentOS 5.x or newer (or Fedora Linux) user type the following command:
  22. # yum install rsync
  23. Always use rsync over ssh
  24.  
  25. Since rsync does not provide any security while transferring data it is recommended that you use rsync over ssh session. This allows a secure remote connection. Now let us see some examples of rsync command.
  26. Comman rsync command options
  27.  
  28. --delete : delete files that don't exist on sender (system)
  29. -v : Verbose (try -vv for more detailed information)
  30. -e "ssh options" : specify the ssh as remote shell
  31. -a : archive mode
  32. -r : recurse into directories
  33. -z : compress file data
  34.  
  35. Task : Copy file from a local computer to a remote server
  36.  
  37. Copy file from /www/backup.tar.gz to a remote server called openbsd.nixcraft.in
  38. $ rsync -v -e ssh /www/backup.tar.gz jerry@openbsd.nixcraft.in:~
  39. Output:
  40.  
  41. Password:
  42. sent 19099 bytes received 36 bytes 1093.43 bytes/sec
  43. total size is 19014 speedup is 0.99
  44.  
  45. Please note that symbol ~ indicate the users home directory (/home/jerry).
  46. Task : Copy file from a remote server to a local computer
  47.  
  48. Copy file /home/jerry/webroot.txt from a remote server openbsd.nixcraft.in to a local computer's /tmp directory:
  49. $ rsync -v -e ssh jerry@openbsd.nixcraft.in:~/webroot.txt /tmp
  50. Task: Synchronize a local directory with a remote directory
  51.  
  52. $ rsync -r -a -v -e "ssh -l jerry" --delete /local/webroot openbsd.nixcraft.in:/webroot
  53. Task: Synchronize a remote directory with a local directory
  54.  
  55. $ rsync -r -a -v -e "ssh -l jerry" --delete openbsd.nixcraft.in:/webroot/ /local/webroot
  56. Task: Synchronize a local directory with a remote rsync server or vise-versa
  57.  
  58. $ rsync -r -a -v --delete rsync://rsync.nixcraft.in/cvs /home/cvs
  59. OR
  60. $ rsync -r -a -v --delete /home/cvs rsync://rsync.nixcraft.in/cvs
  61. Task: Mirror a directory between my "old" and "new" web server/ftp
  62.  
  63. You can mirror a directory between my "old" (my.old.server.com) and "new" web server with the command (assuming that ssh keys are set for password less authentication)
  64. $ rsync -zavrR --delete --links --rsh="ssh -l vivek" my.old.server.com:/home/lighttpd /home/lighttpd
  65. Read related previous articles
  66.  
  67. How do I sync data between two Load balanced Linux/UNIX servers?
  68. How do I sync data between two Load balanced Windows 2003 servers?
  69.  
  70. Other options - rdiff and rdiff-backup
  71.  
  72. The rdiff command uses the rsync algorithm. A utility called rdiff-backup has been created which is capable of maintaining a backup mirror of a file or directory over the network, on another server. rdiff-backup stores incremental rdiff deltas with the backup, with which it is possible to recreate any backup point. Next time I will write about these utilities.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement