{"id":1375,"date":"2017-08-14T12:33:39","date_gmt":"2017-08-14T12:33:39","guid":{"rendered":"https:\/\/www.xsofthost.com\/help\/?p=1375"},"modified":"2021-03-15T15:10:17","modified_gmt":"2021-03-15T15:10:17","slug":"backup-files-in-linux-using-rsync-command-line","status":"publish","type":"post","link":"https:\/\/www.xsofthost.com\/help\/backup-files-in-linux-using-rsync-command-line\/","title":{"rendered":"Backup Files in Linux using Rsync Command Line"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1375\" class=\"elementor elementor-1375\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-780ccb1 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"780ccb1\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-15eb158\" data-id=\"15eb158\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-248f8e9 elementor-widget elementor-widget-text-editor\" data-id=\"248f8e9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-weight: var( --e-global-typography-text-font-weight );\">linux rsync\u00a0 stands for remote sync which was written by <a href=\"https:\/\/en.wikipedia.org\/wiki\/Andrew_Tridgell\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Andrew Tridgell<\/a> and Paul Mackerras back in 1996. It\u2019s one of the most used and power \u2018tools\u2019 in the UNIX world and almost a standard for syncing data. Most Linux distributions have rsync pre-installed, but if it\u2019s not there you can install the \u2018rsync\u2019 package for your distribution.<\/span><\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-dfb82d8 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"dfb82d8\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-5d699aa\" data-id=\"5d699aa\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-ad78485 elementor-widget elementor-widget-heading\" data-id=\"ad78485\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">What is Rsync<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bfd55c7 elementor-widget elementor-widget-text-editor\" data-id=\"bfd55c7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\tRsync is an extremely powerful tool and does more than just make copies of your files on your system. it also synchronize files on two directories on the same Server; or synchronize files and\/or directories on two different systems on the same network.\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7900c64 elementor-widget elementor-widget-heading\" data-id=\"7900c64\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Advantages and features of Rsync command<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fd09cb6 elementor-widget elementor-widget-text-editor\" data-id=\"fd09cb6\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<ul>\n<li><strong>rsync<\/strong>\u00a0faster than\u00a0<strong>scp<\/strong>\u00a0(Secure Copy) ,because\u00a0<strong>rsync<\/strong>\u00a0uses remote-update protocol which allows to transfer just the differences between two sets of files. First time rysnc copies the whole content of a file or a directory from source to destination then the next time rsync copies only the changed blocks and bytes to the destination.<\/li>\n<li>Rsync consumes less bandwidth because it uses compression and decompression method while sending and receiving data both ends.<\/li>\n<li>Rsync Supports copying links, devices, owners, groups and permissions.<\/li>\n<li>its support remote copy.<\/li>\n<\/ul>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d6d1620 elementor-widget elementor-widget-heading\" data-id=\"d6d1620\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Install rsync in Linux<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-430dffd elementor-widget elementor-widget-text-editor\" data-id=\"430dffd\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\tFor Red Hat and Centos\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-de157ab elementor-widget elementor-widget-code-highlight\" data-id=\"de157ab\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"prismjs-okaidia copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>yum install rsync<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-dd96037 elementor-widget elementor-widget-text-editor\" data-id=\"dd96037\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\tOn Debian based systems\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-71eb6c3 elementor-widget elementor-widget-code-highlight\" data-id=\"71eb6c3\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"prismjs-okaidia copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>apt-get install rsync<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6a08581 elementor-widget elementor-widget-heading\" data-id=\"6a08581\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">The basic syntax of rsync<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d509d46 elementor-widget elementor-widget-text-editor\" data-id=\"d509d46\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\trsync option Source-Directory Destination-Directory\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-dbaea45 elementor-widget elementor-widget-heading\" data-id=\"dbaea45\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Common linux rsync options command<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6a82758 elementor-widget elementor-widget-text-editor\" data-id=\"6a82758\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<ul>\n<li><strong>-v<\/strong>\u00a0: verbose<\/li>\n<li><strong>-r<\/strong>\u00a0: copies data recursively (but don\u2019t preserve timestamps and permission while transferring data).<\/li>\n<li><strong>-a<\/strong>\u00a0: archive mode, archive mode allows copying files recursively .<\/li>\n<li><strong>-z<\/strong>\u00a0: Saves bandwidth over the network, by compress file data<\/li>\n<li><strong>-h<\/strong>\u00a0: human-readable, output numbers in a human-readable format<\/li>\n<li><strong>-P<\/strong>\u00a0: for partial progress.<\/li>\n<li><strong>-e<\/strong>\u00a0: To specify protocol name you want to use,for example if you are going to use the rsync with ssh protocol to backup or copy data remotely.<\/li>\n<\/ul>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-17f9564 elementor-widget elementor-widget-heading\" data-id=\"17f9564\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\">Use of \u2013\u2013 delete Option : \n<\/h4>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9520ba5 elementor-widget elementor-widget-text-editor\" data-id=\"9520ba5\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\tIf you have two sets of directories synced with each other. AND some files or directories deleted ,and you need to be sure that those files or folders will be delete on the destination as well? You need to use the \u2018- \u2013 delete\u2019 option which will take care of such cases.The command becomes:\n\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5bb05d8 elementor-widget elementor-widget-code-highlight\" data-id=\"5bb05d8\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"prismjs-okaidia copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>rsync -a \u2013-delete Source Destination<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5950c6c elementor-widget elementor-widget-heading\" data-id=\"5950c6c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\">How to sync directories (remotely) over network<\/h4>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3555fdb elementor-widget elementor-widget-text-editor\" data-id=\"3555fdb\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\tssh protocol help you to backup remotely. Use the following syntax to sync a remote directory with a local directory: <b>Please note that you have to choose option -e to use ssh protocol.<\/b>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-54df1c8 elementor-widget elementor-widget-code-highlight\" data-id=\"54df1c8\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"prismjs-okaidia copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>rsync -avzP \u2013\u2013delete -e ssh user@remote-server:source-directory \/local-server-destination_directory\/<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8e165aa elementor-widget elementor-widget-heading\" data-id=\"8e165aa\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Automate rsync backup<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9aa33e5 elementor-widget elementor-widget-text-editor\" data-id=\"9aa33e5\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Now the best benefit and powerful part is to automate backup.<br \/>You can achieve this feature by creating cron job on Linux OS.<br \/>Run \u2018<b>crontab -e\u2019<\/b> to create cron jobs. It will open an empty file where you can configure the command that you want to run at a desired time.<br \/>The format of crontab is quite simple; just pass the five fields followed by your rsync command:<\/p>\n<p><strong>m h dm m dw command<\/strong><\/p>\n<p>the following will run corn rsync every day at 6.30 PM:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3d11f15 elementor-widget elementor-widget-code-highlight\" data-id=\"3d11f15\" data-element_type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-sass \">\n\t\t\t\t<code readonly=\"true\" class=\"language-sass\">\n\t\t\t\t\t<xmp>30 18 * * * rsync your-source your-Destination<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>linux rsync\u00a0 stands for remote sync which was written by Andrew Tridgell and Paul Mackerras back in 1996. It\u2019s one of the most used and power \u2018tools\u2019 in the UNIX world and almost a standard for syncing data. Most Linux distributions have rsync pre-installed, but if it\u2019s not there you can install the \u2018rsync\u2019 package [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":354,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[41],"tags":[185,42,50,149,74],"_links":{"self":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts\/1375"}],"collection":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/comments?post=1375"}],"version-history":[{"count":47,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts\/1375\/revisions"}],"predecessor-version":[{"id":3887,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/posts\/1375\/revisions\/3887"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/media\/354"}],"wp:attachment":[{"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/media?parent=1375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/categories?post=1375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xsofthost.com\/help\/wp-json\/wp\/v2\/tags?post=1375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}