{"id":505,"date":"2022-04-28T10:26:43","date_gmt":"2022-04-28T08:26:43","guid":{"rendered":"https:\/\/workerbase.org\/wordpress\/?p=505"},"modified":"2026-02-03T12:46:17","modified_gmt":"2026-02-03T11:46:17","slug":"rsync-with-bash-scripting-for-backup","status":"publish","type":"post","link":"https:\/\/arkenidar.com\/wordpress\/2022\/04\/28\/rsync-with-bash-scripting-for-backup\/","title":{"rendered":"rsync with BASH scripting for backup"},"content":{"rendered":"\n<p>Introduction: I needed to backup copy from my remote server (arkenidar.com personal website) to my local computer, incrementally, 3 important directories, into my Dropbox so to keep them. This does not keep into account database backup so this plus servmask&#8217;s &#8220;All-in-One WP Migration plugin&#8221; enabled me to move my partially WordPress partially &#8220;custom HTML&#8221; personal web site from Linode to DigitalOcean, after also screwing an Ubuntu&#8217;s release upgrade, with ensuing security concerns (php sources were exposed also config php files, because they weren&#8217;t processed by misconfiguration after upgrade).<\/p>\n\n\n\n<p>Scripting enable to ease the automating of keeping this.<\/p>\n\n\n\n<p>There are variables for configuring for personal use. The variable RSOPT (rsync options) enable to inject options to the rsync use.<\/p>\n\n\n\n<p>I am publishing because initially it was very basic and simple then it kind of grew, so I am showing it. And pertinent feedback is esteemed valuable by me.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env sh\n\n# env RSOPT=\"--dry-run\" ~\/Dropbox\/my-www\/rsync-backup-www.sh\n# env RSOPT=\"--dry-run --delete\" ~\/Dropbox\/my-www\/rsync-backup-www.sh\n\nHOST=arkenidar.com\nTHIS=backup-www\nDEST=~\/Dropbox\/my-www\/$THIS\nmkdir --parents $DEST\nline=\"-------------------------------------------------\"\necho $line\ncd $DEST &amp;&amp; RSYNC=\"rsync $RSOPT -arvz root@$HOST:\" &amp;&amp; \\\necho \"&gt;&gt; $RSYNC\/root .\" &amp;&amp; $RSYNC\/root . &amp;&amp; echo $line &amp;&amp; \\\necho \"&gt;&gt; $RSYNC\/etc\/apache2 .\" &amp;&amp; $RSYNC\/etc\/apache2 . &amp;&amp; echo $line &amp;&amp; \\\necho \"&gt;&gt; $RSYNC\/var\/www .\" &amp;&amp; $RSYNC\/var\/www . &amp;&amp; echo $line &amp;&amp; \\\necho \"&gt;&gt; backup DONE (BUT databases aren't included)\"\necho $line\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/arkenidar.com\/wordpress\/wp-content\/uploads\/2022\/04\/code.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/arkenidar.com\/wordpress\/wp-content\/uploads\/2022\/04\/execution.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>then became:<\/p>\n\n\n\n<p>It has a FOR loop with BREAK condition, mimicking the &#8220;command1 &amp;&amp; command2 &amp;&amp; command3&#8221; semantics.<\/p>\n\n\n\n<p>It prints the command before executing it (ala Makefile perhaps), by custom code.<\/p>\n\n\n\n<p>This is my first more meaningful BASH script so I am a beginner in this. And it spanned Ubuntu Server, KUbuntu, Manjaro, Windows 10 (Cygwin, Mingw, Termius for shells). Also a use of Dropbox is used to keep them somewhere safe but accessible, other options? Someone told me of Deja-Dup but is it for remote servers? Of course one can creatively find other ways, evaluate them together using our skills and experiences, so I am asking and presenting this as clear as I manage to.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nHOST=arkenidar.com\nTHIS=backup-www\nDEST=~\/Dropbox\/my-www\/$THIS\nmkdir --parents $DEST\nline=\"-------------------------------------------------\"\necho $line\ncd $DEST &amp;&amp; RSYNC=\"rsync $RSOPT -arvz root@$HOST:\" &amp;&amp; \\\n\nfor dir in \/root \/etc\/apache2 \/var\/www ; do\nCOMMAND=\"$RSYNC$dir .\"\necho \"&gt;&gt; $COMMAND\" &amp;&amp; $COMMAND\n\nif &#91; $? -ne 0 ] ; then\n    echo $line\n    echo \"&gt;&gt; Exit status is FAILURE, exiting.\"\n    echo $line\n    exit 1\nfi\n\necho $line\ndone\n\necho \"&gt;&gt; backup DONE (BUT databases aren't included)\"\necho $line<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/arkenidar.com\/wordpress\/wp-content\/uploads\/2022\/04\/Screenshot_20220429_100417-focus.png\" alt=\"\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: I needed to backup copy from my remote server (arkenidar.com personal website) to my local computer, incrementally, 3 important directories, into my Dropbox so to keep them. This does not keep into account database backup so this plus servmask&#8217;s &#8220;All-in-One WP Migration plugin&#8221; enabled me to move my partially WordPress partially &#8220;custom HTML&#8221; personal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-505","post","type-post","status-publish","format-standard","hentry","category-senza-categoria"],"_links":{"self":[{"href":"https:\/\/arkenidar.com\/wordpress\/wp-json\/wp\/v2\/posts\/505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arkenidar.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arkenidar.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arkenidar.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arkenidar.com\/wordpress\/wp-json\/wp\/v2\/comments?post=505"}],"version-history":[{"count":12,"href":"https:\/\/arkenidar.com\/wordpress\/wp-json\/wp\/v2\/posts\/505\/revisions"}],"predecessor-version":[{"id":613,"href":"https:\/\/arkenidar.com\/wordpress\/wp-json\/wp\/v2\/posts\/505\/revisions\/613"}],"wp:attachment":[{"href":"https:\/\/arkenidar.com\/wordpress\/wp-json\/wp\/v2\/media?parent=505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arkenidar.com\/wordpress\/wp-json\/wp\/v2\/categories?post=505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arkenidar.com\/wordpress\/wp-json\/wp\/v2\/tags?post=505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}