{"id":601,"date":"2012-07-02T09:01:09","date_gmt":"2012-07-02T09:01:09","guid":{"rendered":"http:\/\/www.plugged.in\/?p=601"},"modified":"2012-07-02T09:01:09","modified_gmt":"2012-07-02T09:01:09","slug":"rsync-backup-and-restores-files","status":"publish","type":"post","link":"https:\/\/www.veriteknik.net.tr\/en\/rsync-backup-and-restores-files\/","title":{"rendered":"RSYNC &#8211; Backup and Restores Files"},"content":{"rendered":"<p><strong>rsync<\/strong> is a very useful tool when it comes to backing up multiple files from remote or local targets. Below are a few nice examples you can use.<\/p>\n<p>To backup the whole contents of your \/home directory to let&#8217;s say a usb disk, use the following.<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rsync -av \/home \/media\/usb_disk<\/pre>\n<p>Note that this will create a directory to the path<strong> \/media\/usb_disk\/home<\/strong><br \/>\nIf you want everything under \/home directory to be copied directly to \/media\/usb_disk (without the &#8220;home&#8221; directory under the disk) you can use this,<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rsync -av \/home\/ \/media\/usb_disk<\/pre>\n<p>This is useful when you&#8217;re planning to move your \/home to a new mount point. So the trailing <strong>\/<\/strong> means &#8220;copy the contents only, not the directory itself&#8221;.<\/p>\n<p>In these commands, the -a argument is very important, it means archive mode and will preserve everything recursively including symbolic links, devices, attributes, permissions, ownerships etc.<\/p>\n<p>To copy some content to a remote machine with ssh access,<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rsync -av -e ssh \/home some_user@192.168.2.5:\/backups<\/pre>\n<p>To make the transfer with compression on, use the <strong>-z<\/strong> argument.<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rsync -avz -e ssh \/home some_user@192.168.2.5:\/backups<\/pre>\n<p>You can copy files from remote server to your local, and use the progress argument to see the status of the transfer,<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rsync -avz --progress -e ssh some_user@192.168.2.5:\/backups \/path\/to\/local\/directory<\/pre>\n<p>You can delete the files in the target that are not present in the source,<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rysnc -avz --delete -e ssh some_user@192.168.2.5:\/backups \/path\/to\/local\/directory<\/pre>\n<p>Or you can sync only current files, and NOT copy new ones,<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rysnc -avz --existing -e ssh some_user@192.168.2.5:\/backups \/path\/to\/local\/directory<\/pre>\n<p>You can tell rsync to only include some files and excluse some others,<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rsync -avz --include '*.conf' --exclude '*' --existing -e ssh some_user@192.168.2.5:\/backups \/path\/to\/local\/directory<\/pre>\n<p>The above example will only update <strong>.conf<\/strong> files accross the backup server and local one, without writing new files.<\/p>\n<p>You can limit the file transfer size so that you can transfer big files,<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rsync -avz --max-size='5M' -e ssh some_user@192.168.2.5:\/backups \/path\/to\/local\/directory<\/pre>\n<p>The best part of rsync is that in only transfers the part of the files that have been altered. To achieve this it uses md5checksums which can cost you some CPU time. If you don&#8217;t have bandwidth problems but want to offload CPU usage while syncing your files, you can tell rsync to copy the WHOLE file and skip the md5 checking.<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rsync -avzW -e ssh some_user@192.168.2.5:\/backups \/path\/to\/local\/directory<\/pre>\n<p>Sometimes the path of rsync on the remote server might be different, in these cases we should specify it. Below is a very universal format of the rsync command.<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">rsync -arzgopv some_user@192.168.2.5:\/backups \/path\/to\/local\/directory --rsync-path=\/usr\/bin\/rsync<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>rsync is a very useful tool when it comes to backing up multiple files from remote or local targets. Below are a few nice examples you can use. To backup the whole contents of your \/home directory to let&#8217;s say a usb disk, use the following. rsync -av \/home \/media\/usb_disk Note that this will create [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[370],"tags":[537,538],"yst_prominent_words":[1264,1258,1096,827,1266,1248,1261,1204,711,1257,1263,710,866,817,1260,337,1259,1262,1265,642],"class_list":["post-601","post","type-post","status-publish","format-standard","hentry","category-linux","tag-backup","tag-rsync"],"jetpack_featured_media_url":"","uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Mustafa Emre Ayd\u0131n","author_link":"https:\/\/www.veriteknik.net.tr\/en\/author\/eaydin\/"},"uagb_comment_info":0,"uagb_excerpt":"rsync is a very useful tool when it comes to backing up multiple files from remote or local targets. Below are a few nice examples you can use. To backup the whole contents of your \/home directory to let&#8217;s say a usb disk, use the following. rsync -av \/home \/media\/usb_disk Note that this will create&hellip;","_links":{"self":[{"href":"https:\/\/www.veriteknik.net.tr\/en\/wp-json\/wp\/v2\/posts\/601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veriteknik.net.tr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veriteknik.net.tr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veriteknik.net.tr\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veriteknik.net.tr\/en\/wp-json\/wp\/v2\/comments?post=601"}],"version-history":[{"count":0,"href":"https:\/\/www.veriteknik.net.tr\/en\/wp-json\/wp\/v2\/posts\/601\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.veriteknik.net.tr\/en\/wp-json\/wp\/v2\/media?parent=601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veriteknik.net.tr\/en\/wp-json\/wp\/v2\/categories?post=601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veriteknik.net.tr\/en\/wp-json\/wp\/v2\/tags?post=601"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.veriteknik.net.tr\/en\/wp-json\/wp\/v2\/yst_prominent_words?post=601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}