{"id":116,"date":"2021-09-17T06:10:29","date_gmt":"2021-09-17T06:10:29","guid":{"rendered":"http:\/\/webhostingpune.co.in\/blog\/?p=116"},"modified":"2021-09-17T06:10:31","modified_gmt":"2021-09-17T06:10:31","slug":"how-to-use-rsync-to-sync-with-a-remote-system","status":"publish","type":"post","link":"https:\/\/webhostingpune.co.in\/blog\/how-to-use-rsync-to-sync-with-a-remote-system\/","title":{"rendered":"How To Use Rsync to Sync with a Remote System"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Syncing to a remote system is trivial if you have SSH access to the remote machine and\u00a0<code>rsync<\/code>\u00a0installed on both sides. Once you have SSH access verified between the two machines, you can sync the\u00a0<code>dir1<\/code>\u00a0folder from earlier to a remote computer by using this syntax<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -a ~\/dir1 username@remote_host:destination_directory\r<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is called a \u201cpush\u201d operation because it pushes a directory from the local system to a remote system. The opposite operation is \u201cpull\u201d. It is used to sync a remote directory to the local system. If the\u00a0<code>dir1<\/code>\u00a0were on the remote system instead of our local system, the syntax would be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -a username@remote_host:\/home\/username\/dir1 place_to_sync_on_local_machine\r\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Like\u00a0<code>cp<\/code>\u00a0and similar tools, the source is always the first argument, and the destination is always the second.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Useful Options for Rsync<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Rsync provides many options for altering the default behavior of the utility. We have already discussed some of the more necessary flags.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are transferring files that have not already been compressed, like text files, you can reduce the network transfer by adding compression with the\u00a0<code>-z<\/code>\u00a0option:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">rsync -az source destination<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The\u00a0<code>-P<\/code>\u00a0flag is very helpful. It combines the flags\u00a0<code>--progress<\/code>\u00a0and\u00a0<code>--partial<\/code>. The first of these gives you a progress bar for the transfers and the second allows you to resume interrupted transfers:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -azP source destination\r<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In order to keep two directories truly in sync, it is necessary to delete files from the destination directory if they are removed from the source. By default, rsync does not delete anything from the destination directory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can change this behavior with the\u00a0<code>--delete<\/code>\u00a0option. Before using this option, use the\u00a0<code>--dry-run<\/code>\u00a0option and do testing to prevent data loss:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -a --delete source destination\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -a --exclude=pattern_to_exclude source destination\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -a --exclude=pattern_to_exclude --include=pattern_to_include source destination\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>rsync -a --delete --backup --backup-dir=\/path\/to\/backups \/path\/to\/source destination\r\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Syncing to a remote system is trivial if you have SSH access to the remote machine and\u00a0rsync\u00a0installed on both sides. Once you have SSH access verified between the two machines, you can sync the\u00a0dir1\u00a0folder from earlier to a remote computer by using this syntax This is called a \u201cpush\u201d operation because it pushes a directory from the local system to a remote system. The opposite operation is \u201cpull\u201d. It is used to sync a remote directory to the local system. If the\u00a0dir1\u00a0were on the remote system instead of our local system, the syntax would be: Like\u00a0cp\u00a0and similar tools, the source is always the first argument, and the destination is always the second. Useful Options for Rsync Rsync provides many options for altering the default behavior of the utility. We have already discussed some of the more necessary flags. If you are transferring files that have not already been compressed, like text files, you can reduce the network transfer by adding compression with the\u00a0-z\u00a0option: rsync -az source destination The\u00a0-P\u00a0flag is very helpful. It combines the flags\u00a0&#8211;progress\u00a0and\u00a0&#8211;partial. The first of these gives you a progress bar for the transfers and the second allows you to resume interrupted transfers: In order to keep two directories truly in sync, it is necessary to delete files from the destination directory if they are removed from the source. By default, rsync does not delete anything from the destination directory. We can change this behavior with the\u00a0&#8211;delete\u00a0option. Before using this option, use the\u00a0&#8211;dry-run\u00a0option and do testing to prevent data loss:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-116","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":1,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":117,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions\/117"}],"wp:attachment":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}