{"id":2047,"date":"2016-06-22T16:28:34","date_gmt":"2016-06-22T20:28:34","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=2047"},"modified":"2016-09-29T17:13:04","modified_gmt":"2016-09-29T21:13:04","slug":"use-rsync","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/use-rsync\/","title":{"rendered":"How to use rsync"},"content":{"rendered":"<p>Rsync is a versatile tool. Similar in some ways to the generic cp command, rsync does so much more. It can make and restore backups, copy files with metadata intact, and perform a host of other tasks where file synchronization and integrity are important. It also uses its own protocol or works via SSH, making it a great tool for everything from backing up local laptops to administering fleets of servers. Even so, it is complicated. Below you&#8217;ll find an introduction to some of its most common features and command line flags.<\/p>\n<h2>Getting Started<\/h2>\n<p>To complete this guide, you will need the following:<br \/>\n\u2022 1 Node (<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\">Cloud Server<\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\">Dedicated Server<\/a>) with a clean version of Linux installed.<br \/>\n\u2022 Later steps will require a second Linux server with which to synchronize files.<\/p>\n<h2>Tutorial<\/h2>\n<p>We&#8217;ll start by making two directories for synchronizing files.<\/p>\n<p><code> cd \/root<br \/>\n mkdir test1<br \/>\n mkdir test2<\/code><\/p>\n<p>Now let&#8217;s create a file in test1 and see how rsync copies it to test2.<\/p>\n<p><code>  touch \/root\/test1\/test-file.txt<br \/>\n rsync -r \/root\/test1\/ \/root\/test2\/<\/code><\/p>\n<p>&#8220;-r&#8221; means &#8220;recursive.&#8221; It copies all the files in the source directory to the second, recursing into subdirectories. Another convenient shortcut is the &#8220;-a&#8221; option. This switch archives the source to the destination, activating the &#8220;-r&#8221; flag and also copying metadata such as permissions and modification times.<\/p>\n<p><code>  rsync -a \/root\/test1\/ \/root\/test2\/<\/code><\/p>\n<p>After this command, you&#8217;ll see your files synchronized to \/root\/test2.<\/p>\n<p><code>  ls \/root\/test2\/<br \/>\n test-file.txt<\/code><\/p>\n<p>Next let&#8217;s add a remote server into the mix. This example copies a complete directory from one server to another.<\/p>\n<p><code>  rsync -a \/root\/test1\/ username@destination_ip:\/destination\/folder\/<\/code><\/p>\n<p>Here are some additional helpful command line flags to increase rsync&#8217;s usefulness:<\/p>\n<p>&#8220;-v&#8221;: This flag increases verbosity, providing additional information on the stages of the synchronization.<\/p>\n<p><code>  rsync -av \/root\/test1\/ \/root\/test2\/<br \/>\nsending incremental file list<br \/>\n.\/<br \/>\ntest-file.txt1<br \/>\ntest-file.txt10<br \/>\ntest-file.txt11<br \/>\ntest-file.txt12<br \/>\ntest-file.txt13<br \/>\ntest-file.txt14<br \/>\ntest-file.txt15<br \/>\ntest-file.txt16<br \/>\ntest-file.txt17<br \/>\ntest-file.txt18<br \/>\ntest-file.txt19<br \/>\ntest-file.txt2<br \/>\ntest-file.txt3<br \/>\ntest-file.txt4<br \/>\ntest-file.txt5<br \/>\ntest-file.txt6<br \/>\ntest-file.txt7<br \/>\ntest-file.txt8<br \/>\ntest-file.txt9<br \/>\nsent 922 bytes  received 376 bytes  2596.00 bytes\/sec<br \/>\ntotal size is 0  speedup is 0.00<\/code><\/p>\n<p>&#8220;&#8211;delete&#8221;: Say test2 has 20 files, and test1 has only 19 because one was removed. This option synchronizes both directories, deleting any files not present in each. In the above scenario, both test1 and test2 will end up with 19 files because the operation will delete the missing file from test2.<\/p>\n<p><code>  touch \/root\/test1\/test-file.txt{1..19}<br \/>\n touch \/root\/test2\/test-file.txt{1..20}<br \/>\n  ls \/root\/test1\/<br \/>\ntest-file.txt1   test-file.txt11  test-file.txt13  test-file.txt15  test-file.txt17  test-file.txt19  test-file.txt3  test-file.txt5  test-file.txt7  test-file.txt9<br \/>\ntest-file.txt10  test-file.txt12  test-file.txt14  test-file.txt16  test-file.txt18  test-file.txt2   test-file.txt4  test-file.txt6  test-file.txt8<\/code><\/p>\n<p><code>  ls \/root\/test2\/<br \/>\n test-file.txt1   test-file.txt11  test-file.txt13  test-file.txt15  test-file.txt17  test-file.txt19  test-file.txt20  test-file.txt4  test-file.txt6  test-file.txt8<br \/>\ntest-file.txt10  test-file.txt12  test-file.txt14  test-file.txt16  test-file.txt18  test-file.txt2   test-file.txt3   test-file.txt5  test-file.txt7  test-file.txt9<\/code><\/p>\n<p><code>  rsync -a --delete \/root\/test1\/ \/root\/test2\/<br \/>\n ls \/root\/test2\/<br \/>\ntest-file.txt1   test-file.txt11  test-file.txt13  test-file.txt15  test-file.txt17  test-file.txt19  test-file.txt3  test-file.txt5  test-file.txt7  test-file.txt9<br \/>\ntest-file.txt10  test-file.txt12  test-file.txt14  test-file.txt16  test-file.txt18  test-file.txt2   test-file.txt4  test-file.txt6  test-file.txt8<\/code><\/p>\n<p>As with any other rsync flags, &#8220;&#8211;delete&#8221; works across server boundaries.<\/p>\n<p><code> rsync -a --delete \/root\/test1\/ username@destination_ip\/root\/test2\/<\/code><\/p>\n<h2>Conclusion<\/h2>\n<p>A good understanding of rsync is beneficial for any developer or system administrator. It can both perform a quick copy or orchestrate a full backup, and is invaluable for many day-to-day Linux administrative tasks. If this guide was helpful to you, kindly share it with others who may also be interested. <\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Rsync is a versatile tool. Similar in some ways to the generic cp command, rsync does so much more. It can make and restore backups, copy files with metadata intact, and perform a host of other tasks where file synchronization and integrity are important. It also uses its own protocol or works via SSH, making<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-2047","post","type-post","status-publish","format-standard","hentry","category-web-hosting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to use rsync - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will show you how to use rsync to create and restore backups, copy files with metadata and more. Read now !\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/use-rsync\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use rsync - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will show you how to use rsync to create and restore backups, copy files with metadata and more. Read now !\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/use-rsync\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-22T20:28:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-09-29T21:13:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"963\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/use-rsync\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/use-rsync\/\",\"name\":\"How to use rsync - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"datePublished\":\"2016-06-22T20:28:34+00:00\",\"dateModified\":\"2016-09-29T21:13:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"This tutorial will show you how to use rsync to create and restore backups, copy files with metadata and more. Read now !\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/use-rsync\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/use-rsync\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/use-rsync\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to use rsync\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\/\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use rsync - Globo.Tech","description":"This tutorial will show you how to use rsync to create and restore backups, copy files with metadata and more. Read now !","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.globo.tech\/learning-center\/use-rsync\/","og_locale":"en_US","og_type":"article","og_title":"How to use rsync - Globo.Tech","og_description":"This tutorial will show you how to use rsync to create and restore backups, copy files with metadata and more. Read now !","og_url":"https:\/\/www.globo.tech\/learning-center\/use-rsync\/","og_site_name":"Globo.Tech","article_published_time":"2016-06-22T20:28:34+00:00","article_modified_time":"2016-09-29T21:13:04+00:00","og_image":[{"width":1920,"height":963,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png","type":"image\/png"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/use-rsync\/","url":"https:\/\/www.globo.tech\/learning-center\/use-rsync\/","name":"How to use rsync - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-06-22T20:28:34+00:00","dateModified":"2016-09-29T21:13:04+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"This tutorial will show you how to use rsync to create and restore backups, copy files with metadata and more. Read now !","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/use-rsync\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/use-rsync\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/use-rsync\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How to use rsync"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=2047"}],"version-history":[{"count":4,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2047\/revisions"}],"predecessor-version":[{"id":2834,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2047\/revisions\/2834"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=2047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=2047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=2047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}