{"id":128,"date":"2019-02-01T03:44:07","date_gmt":"2019-02-01T03:44:07","guid":{"rendered":"https:\/\/mumbaiwebhosting.co.in\/portal\/?p=128"},"modified":"2022-02-25T02:47:21","modified_gmt":"2022-02-25T02:47:21","slug":"how-to-use-rsync-command-in-linux","status":"publish","type":"post","link":"https:\/\/mumbaiwebhosting.co.in\/portal\/how-to-use-rsync-command-in-linux\/","title":{"rendered":"How to use rsync command in linux"},"content":{"rendered":"\r\n<p>Hi folks to day we are going to see about rsync\u00a0(Remote Sync) and How to use rsync command in linux .It is a command which most commonly used for\u00a0copying\u00a0and\u00a0synchronizing\u00a0files and directories\u00a0remotely\u00a0as well as\u00a0locally\u00a0in\u00a0Linux.Using\u00a0\u00a0rsync\u00a0command we can copy and synchronize our data remotely and locally across directories, across disks and networks, perform data backups and mirroring between two Linux machines.<\/p>\r\n\r\n\r\n\r\n<h4>Some beneifits and features of Rsync command<\/h4>\r\n\r\n\r\n\r\n<ul>\r\n<li>It efficiently copies and sync files to or from a remote system.<\/li>\r\n<li>Supports copying links, devices, owners, groups and permissions.<\/li>\r\n<li>Rsync consumes less\u00a0bandwidth\u00a0.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h4>syntax of rsync command<\/h4>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"># rsync options source destination<\/pre>\r\n\r\n\r\n\r\n<h4>Some common options used with rsync commands<\/h4>\r\n\r\n\r\n\r\n<ul>\r\n<li><strong>-v<\/strong>\u00a0: verbose<\/li>\r\n<li><strong>-r<\/strong>\u00a0: copies data recursively (but don\u2019t preserve timestamps and permission while transferring data.<\/li>\r\n<li><strong>-a<\/strong>\u00a0: archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user &amp; group ownerships and timestamps.<\/li>\r\n<li><strong>-z<\/strong>\u00a0: compress file data.<\/li>\r\n<li><strong>-h<\/strong>\u00a0: human-readable, output numbers in a human-readable format.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h4>Copy\/Sync a File on a Local Computer<\/h4>\r\n\r\n\r\n\r\n<p>This below command will sync a single file on a local machine from one location to another location. Here in this example, a file name\u00a0backup.tar\u00a0needs to be copied or synced to\u00a0\/tmp\/backups\/\u00a0folder.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[root@vps~]# rsync -zvh backup.tar \/tmp\/backups\/\r\ncreated directory \/tmp\/backups\r\nbackup.tar\r\nsent 14.71M bytes  received 31 bytes  3.27M bytes\/sec\r\ntotal size is 16.18M  speedup is 1.10<\/pre>\r\n\r\n\r\n\r\n<h4>Copy\/Sync a Directory on Local Computer<\/h4>\r\n\r\n\r\n\r\n<p>The below command will transfer or sync all the files of from one directory to a different directory in the same machine.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[root@vps~]# rsync -avz rpmpkgs\/ root@103.14.121.87:\/home\/\r\nroot@103.14.121.87's password:\r\nsending incremental file list\r\n.\/\r\nhttpd-2.2.3-82.el5.centos.i386.rpm\r\nmod_ssl-2.2.3-82.el5.centos.i386.rpm\r\nnagios-3.5.0.tar.gz\r\nnagios-plugins-1.4.16.tar.gz\r\nsent 4993369 bytes  received 91 bytes  399476.80 bytes\/sec\r\ntotal size is 4991313  speedup is 1.00<\/pre>\r\n\r\n\r\n\r\n<h4>Copy a File from a Remote Server to a Local Server with SSH<\/h4>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"> [root@vps~]# rsync -avzhe ssh root@103.14.121.87:\/root\/install.log \/tmp\/\r\nroot@103.14.121.87's password:\r\nreceiving incremental file list\r\ninstall.log\r\nsent 30 bytes  received 8.12K bytes  1.48K bytes\/sec\r\ntotal size is 30.74K  speedup is 3.77<\/pre>\r\n\r\n\r\n\r\n<p>To specify a protocol with\u00a0rsync we need to give \u201c-e\u201d option with protocol name which we want to use. Here in this example, We will be using \u201cssh\u201d with \u201c-e\u201d option and perform data transfer.<\/p>\r\n\r\n\r\n\r\n<h4>Copy a File from a Local Server to a Remote Server with SSH<\/h4>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">[root@vps~]# rsync -avzhe ssh backup.tar root@103.14.121.87:\/backups\/\r\nroot@103.14.121.87's password:\r\nsending incremental file list\r\nbackup.tar\r\nsent 14.71M bytes  received 31 bytes  1.28M bytes\/sec\r\ntotal size is 16.18M  speedup is 1.10<\/pre>\r\n\r\n\r\n\r\n<h4>Show Progress While Transferring Data with rsync<\/h4>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"> [root@vps~]# rsync -avzhe ssh --progress \/home\/rpmpkgs root@103.14.121.87:\/root\/rpmpkgs\r\nroot@103.14.121.87's password:\r\nsending incremental file list\r\ncreated directory \/root\/rpmpkgs\r\nrpmpkgs\/\r\nrpmpkgs\/httpd-2.2.3-82.el5.centos.i386.rpm\r\n1.02M 100%        2.72MB\/s        0:00:00 (xfer#1, to-check=3\/5)\r\nrpmpkgs\/mod_ssl-2.2.3-82.el5.centos.i386.rpm\r\n99.04K 100%  241.19kB\/s        0:00:00 (xfer#2, to-check=2\/5)\r\nrpmpkgs\/nagios-3.5.0.tar.gz\r\n1.79M 100%        1.56MB\/s        0:00:01 (xfer#3, to-check=1\/5)\r\nrpmpkgs\/nagios-plugins-1.4.16.tar.gz\r\n2.09M 100%        1.47MB\/s        0:00:01 (xfer#4, to-check=0\/5)\r\nsent 4.99M bytes  received 92 bytes  475.56K bytes\/sec\r\ntotal size is 4.99M  speedup is 1.00<\/pre>\r\n\r\n\r\n\r\n<p>Additionall one more use of r<\/p>\r\n\r\n\r\n\r\n<p>Now, If we have a main web server and a data backup server, the created a daily backup synced it with our backup server, now if we don\u2019t want to keep that local copy of backup in our web server then we have to use the following command,<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"> [root@vps~]# rsync --remove-source-files -zvh backup.tar \/tmp\/backups\/\r\nbackup.tar\r\nsent 14.71M bytes  received 31 bytes  4.20M bytes\/sec\r\ntotal size is 16.18M  speedup is 1.10\r\n<\/pre>\r\n\r\n\r\n<p>[root@tecmint]<\/p>\n\r\n\r\n\r\n<p># ll backup.tar ls: backup.tar: No such file or director<\/p>\r\n\r\n\r\n\r\n<p>Hope this article is helpful to all and helps to know how to use rsync command in linux.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Hi folks to day we are going to see about rsync\u00a0(Remote Sync) and How to use rsync command in linux .It is a command which most commonly used for\u00a0copying\u00a0and\u00a0synchronizing\u00a0files and&#8230; <a class=\"read-more-link\" href=\"https:\/\/mumbaiwebhosting.co.in\/portal\/how-to-use-rsync-command-in-linux\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/mumbaiwebhosting.co.in\/portal\/wp-json\/wp\/v2\/posts\/128"}],"collection":[{"href":"https:\/\/mumbaiwebhosting.co.in\/portal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mumbaiwebhosting.co.in\/portal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mumbaiwebhosting.co.in\/portal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mumbaiwebhosting.co.in\/portal\/wp-json\/wp\/v2\/comments?post=128"}],"version-history":[{"count":2,"href":"https:\/\/mumbaiwebhosting.co.in\/portal\/wp-json\/wp\/v2\/posts\/128\/revisions"}],"predecessor-version":[{"id":156,"href":"https:\/\/mumbaiwebhosting.co.in\/portal\/wp-json\/wp\/v2\/posts\/128\/revisions\/156"}],"wp:attachment":[{"href":"https:\/\/mumbaiwebhosting.co.in\/portal\/wp-json\/wp\/v2\/media?parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mumbaiwebhosting.co.in\/portal\/wp-json\/wp\/v2\/categories?post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mumbaiwebhosting.co.in\/portal\/wp-json\/wp\/v2\/tags?post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}