{"id":6053,"date":"2018-11-06T23:17:50","date_gmt":"2018-11-06T22:17:50","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=6053"},"modified":"2020-06-15T13:27:34","modified_gmt":"2020-06-15T11:27:34","slug":"rsync-sync-and-backup-examples","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/rsync-sync-and-backup-examples\/","title":{"rendered":"rsync: sync and backup examples"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_6053 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_6053')){$('.twoclick_social_bookmarks_post_6053').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"rsync%3A%20sync%20and%20backup%20examples\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Arsync%20is%20a%20powerful%20tool%20for%20syncing%20or%20backup%20folders.%20This%20post%20describes%20the%20parameters%20I%20usually%20use.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/rsync-sync-and-backup-examples\\\/\",\"post_id\":6053,\"post_title_referrer_track\":\"rsync%3A+sync+and+backup+examples\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>rsync is a powerful tool for syncing or backup folders. This post describes the parameters I usually use.<br \/>\n<!--more--><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmichael@debdev ~# rsync -a ~\/MyStuff michael@devdeb2:\/home\/michael\/MyStuff\r\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n -a =&gt; means -rlptgoD\r\n\r\n -r, --recursive             recurse into directories\r\n -l, --links                 copy symlinks as symlinks\r\n -p, --perms                 preserve permissions\r\n -t, --times                 preserve modification times\r\n -g, --group                 preserve group\r\n     --devices               preserve device files (super-user only)\r\n     --specials              preserve special files\r\n -o, --owner                 preserve owner (super-user only)\r\n -D                          same as --devices --specials\r\n  --devices                    preserve device files (super-user only)\r\n  --specials                   preserve special files\r\n<\/pre>\n<p>other very usefull options:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n-P                          same as --partial --progress\r\n  --partial                 keep partially transferred files\r\n  --progress                show progress during transfer\r\n\r\n-u, --update                skip files that are newer on the receiver\r\n\r\n-z, --compress              compress file data during the transfer\r\n\r\n-v, --verbose               increase verbosity\r\n\r\n--stats                 give some file-transfer stats\r\n# Full sync delete files in destination which not exist in source\r\n--delete                delete extraneous files from destination dirs\r\n# On Fullsync just rename a file instead of delete them when it not exist in source\r\n-b --suffix=.bak\r\n\r\n--numeric-ids           don't map uid\/gid values by user\/group name of source and target. Just copy the numerical user\/group ids\r\n<\/pre>\n<p>And as a full command line. This example uses ssh as transport protocol and requires that rsync is installed an both, the source and the target machine.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"> \r\nmichael@debdev ~# rsync -a -P -u -z --stats root@devdeb2:\/srv \/mnt\/sdb2\r\n<\/pre>\n<p>rsync can also be used with a User\/Password respectively a shared secret authentification without ssh.<\/p>\n<p>On the target machine install and start rsync as a daemon.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~# apt-get install rsync\r\nroot@debdev ~# systemctl enable rsync\r\n<\/pre>\n<p>Open respectively create file \/etc\/rsyncd.conf and add a &#8220;Module&#8221;. In this example customized monit files. Explanation: A module exports a directory by a symblic name. uid and gid are the credentials under which the rsync process runs. Means the user needs access to the path defined in the module.<br \/>\n<code><br \/>\n[monit]<br \/>\npath = \/etc\/monit\/conf.d<br \/>\ncomment = Monit<br \/>\nuid = root<br \/>\ngid = root<br \/>\nauth users = monit-replication<br \/>\nsecrets file = \/etc\/rsyncd.secrets<br \/>\n<\/code><br \/>\n\/etc\/rsyncd.secrets<br \/>\n<code><br \/>\nmonit-replication:MySecretPassword<br \/>\n<\/code><\/p>\n<p>On your source machine. Create also a \/etc\/rsyncd.secrets file with just the password as content.<br \/>\n<code><br \/>\nMySecretPassword<br \/>\n<\/code><br \/>\nSet permissions<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev2 ~# chown root:root \/etc\/rsyncd.secrets\r\nroot@debdev2 ~# chmod 400 \/etc\/rsyncd.secrets\r\n<\/pre>\n<p>To run rsync without prompting for the password specify the &#8211;password-file=\/etc\/rsyncd.secrets parameter or set the Environment variable RSYNC_PASSWORD <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev2 ~# export RSYNC_PASSWORD=MySecretPassword\r\n<\/pre>\n<p>Check folder access<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev2 ~# rsync --password-file=\/etc\/rsyncd.secrets rsync:\/\/monit-replication@debdev\/monit\r\n<\/pre>\n<p>And get the folder<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev2 ~# rsync -a -P -u -z --stats --password-file=\/etc\/rsyncd.secrets rsync:\/\/monit-replication@debdev\/monit \/tmp\r\n<\/pre>\n<p>Filters. Note: Default is to includes all. This example copies all pdf files. Importent is to set the include before the exclude filter because the first match determines if a file is copied or not.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev2 ~# rsync -a -P -u -z --stats --include '*.pdf' --exclude '*' --password-file=\/etc\/rsyncd.secrets rsync:\/\/monit-replication@debdev\/monit \/tmp\r\n--include '*.pdf' --exclude '*' \r\n<\/pre>\n<p>To exclude more the one folders use the exclude switch multiple times<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmichael@debdev ~# rsync -a -exclude .cache -exclude Downloads ~\/MyStuff michael@devdeb2:\/home\/michael\/MyStuff\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, rsync is a powerful tool for syncing or backup folders. This post describes the parameters I usually use.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[870,1276],"tags":[1279,1278,1281,217,1456,1280,207,1277],"class_list":["post-6053","post","type-post","status-publish","format-standard","hentry","category-debian","category-rsync","tag-commoin","tag-daemon","tag-define-module","tag-example","tag-exclude-multiple-folders","tag-filters","tag-parameters","tag-rsync"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/6053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=6053"}],"version-history":[{"count":30,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/6053\/revisions"}],"predecessor-version":[{"id":7136,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/6053\/revisions\/7136"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=6053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=6053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=6053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}