{"id":7457,"date":"2024-09-08T01:27:00","date_gmt":"2024-09-08T05:27:00","guid":{"rendered":"https:\/\/www.both.org\/?p=7457"},"modified":"2024-09-08T16:33:15","modified_gmt":"2024-09-08T20:33:15","slug":"heading-to-the-beach","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=7457","title":{"rendered":"Heading to the Beach"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"7457\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<h2 class=\"wp-block-heading\">Synchronizing my laptop with rsync<\/h2>\n\n\n\n<p>Tomorrow, Saturday as I write this, we&#8217;ll be heading to Atlantic Beach, our current favorite. By the time you read it, we&#8217;ll be there enjoying the amazing views including the one in the picture above. We do this every year. We also travel to visit family, and I travel for the occasional conference.<\/p>\n\n\n\n<p>To make my computing life as seamless as possible, I take my <a href=\"https:\/\/system76.com\/\" data-type=\"link\" data-id=\"https:\/\/system76.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">System76<\/a> Serval WS laptop with us &#8212; or me as the case may be. I always sync my home directory from my primary workstation to my laptop, named Voyager3 or vgr3 for short. As that name implies, I have two other System76 laptops. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">My requirements<\/h2>\n\n\n\n<p>A few years ago, I would sync my laptop by hand, just picking out a few directories to copy over from my workstation. That became very tedious and I decided to write a script using the <strong>rsync<\/strong> program. I&#8217;d already started using <strong>rsync<\/strong> for my backups and knew it could do what I needed. My article, <a href=\"https:\/\/www.both.org\/?p=4647\" data-type=\"link\" data-id=\"https:\/\/www.both.org\/?p=4647\" target=\"_blank\" rel=\"noreferrer noopener\">Using rsync for Backup<\/a>, describes how rsync works. <\/p>\n\n\n\n<p>My synchronization program must meet the following requirements:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Be easy to use.<\/li>\n\n\n\n<li>Have a command line user interface that is easily understandable.<\/li>\n\n\n\n<li>Use Bash as its programming language.<\/li>\n\n\n\n<li>Have an integrated help function.<\/li>\n\n\n\n<li>Minimize network traffic.<\/li>\n\n\n\n<li>Be fast.<\/li>\n\n\n\n<li>Run as a non-root user &#8212; namely me.<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The program<\/h2>\n\n\n\n<p>I wrote this Bash program named syncVgr.sh to meet those requirements. It does exactly what I need and does it well and fast. This program, despite the comments, help, and GPL, that I&#8217;ve included, is rather small at only 250 lines, so I&#8217;ve copied it here in its entirety. <\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>#!\/bin\/bash\n################################################################################\n#                               syncVgr.sh                                     #\n#                                                                              #\n# This simple bash program syncs my home directory on host david to the one    #\n# on vgr so that when I travel I have the latest files available.              #\n#                                                                              #\n#                                                                              #\n#                               Changelog                                      #\n#   Date      Who      Description                                             #\n#-----------  -------- --------------------------------------------------------#\n# 2022\/10\/15  dboth    Initial code for concept and initial testing.           #\n# 2022\/11\/15  dboth    Fix initial problems so that excluding cache now works. #\n#                                                                              #\n#                                                                              #\n#                                                                              #\n#                                                                              #\n################################################################################\n################################################################################\n################################################################################\n#                                                                              #\n#  Copyright (C) David Both 2022                                               #\n#  LinuxGeek46@both.org                                                        #\n#                                                                              #\n#  This program is free software; you can redistribute it and\/or modify        #\n#  it under the terms of the GNU General Public License as published by        #\n#  the Free Software Foundation; either version 2 of the License, or           #\n#  (at your option) any later version.                                         #\n#                                                                              #\n#  This program is distributed in the hope that it will be useful,             #\n#  but WITHOUT ANY WARRANTY; without even the implied warranty of              #\n#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #\n#  GNU General Public License for more details.                                #\n#                                                                              #\n#  You should have received a copy of the GNU General Public License           #\n#  along with this program; if not, write to the Free Software                 #\n#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   #\n#                                                                              #\n################################################################################\n################################################################################\n\n\n################################################################################\n# Help                                                                         #\n################################################################################\nhelp()\n{\n   # Display help\n   echo\n   echo \"################################################################################\"\n   echo \"                                 syncVgr.sh\"\n   echo\n   echo \"Performs backups of the \/home\/dboth directory on the host $ThisHost to the \"\n   echo \"laptop $RemoteHostName using rsync. Use this program to sync voyager (vgr) \"\n   echo \"prior to a trip.\"\n   echo\n   echo \"Run this program as the user dboth. The password will be required.\"\n   echo\n   echo \"Syntax: syncVgr.sh -&#91;g|h|s|V]v \"\n   echo \"options:\"\n   echo \"g     Print the GPL license statement.\"\n   echo \"h     Display this help screen.\"\n   echo \"s     Perform the sync operation.\"\n   echo \"t     Test mode. Performs all functions except the actual sync. \"\n   echo \"V     Print version number and exit.\"\n   echo \"v     Verbose mode.\"\n   echo\n   echo \"################################################################################\"\n   echo\n}\n################################################################################\n# Print the GPL license header                                                 #\n################################################################################\ngpl()\n{\n   echo\n   echo \"################################################################################\"\n   echo \"#  Copyright (C) David Both 2022                                               #\"\n   echo \"#  LinuxGeek46@both.org                                                        #\"\n   echo \"#  http:\/\/www.both.org                                                         #\"\n   echo \"#                                                                              #\"\n   echo \"#  This program is free software; you can redistribute it and\/or modify        #\"\n   echo \"#  it under the terms of the GNU General Public License as published by        #\"\n   echo \"#  the Free Software Foundation; either version 3 of the License, or           #\"\n   echo \"#  (at your option) any later version.                                         #\"\n   echo \"#                                                                              #\"\n   echo \"#  This program is distributed in the hope that it will be useful,             #\"\n   echo \"#  but WITHOUT ANY WARRANTY; without even the implied warranty of              #\"\n   echo \"#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #\"\n   echo \"#  GNU General Public License for more details.                                #\"\n   echo \"#                                                                              #\"\n   echo \"#  You should have received a copy of the GNU General Public License along     #\"\n   echo \"#  with this program; if not, If not, see &lt;https:\/\/www.gnu.org\/licenses\/&gt;.     #\"\n   echo \"################################################################################\"\n   echo\n}\n  \n################################################################################\n# Quit nicely with messages as appropriate                                     #\n################################################################################\nQuit()\n{\n   if &#91; $verbose = 1 ]\n      then\n      if &#91; $error = 0 ]\n         then\n         echo \"Program terminated normally\"\n      else\n         echo \"Program terminated with error $error\";\n      fi\n   fi\n   exit\n}\n\n################################################################################\n# Gets simple (Y)es (N)o (Q)uit response from user. Loops until                #\n# one of those responses is detected.                                          #\n################################################################################\nynq()\n{\n   # loop until we get a good answer and break out\n   while &#91; $OK = 0 ]\n   do\n      # Print the message\n      echo -n \"$message (ynq) \"\n      # Now get some input\n      read input\n      # Test the input\n      if &#91; $input = \"yes\" ] || &#91; $input = \"y\" ]\n         then\n         response=\"y\"\n         OK=1\n      elif &#91; $input = \"no\" ] || &#91; $input = \"n\" ]\n         then\n         response=\"n\"\n         OK=1\n      elif &#91; $input = \"help\" ] || &#91; $input = \"h\" ]\n         then\n         help\n      elif &#91; $input = \"q\" ] || &#91; $input = \"quit\" ]\n         then\n         Quit\n      else\n         # Invalid input\n         echo \"INPUT ERROR: Must be y or n or q in lowercase. Please try again.\"\n      fi\n   done\n}\n\n################################################################################\n################################################################################\n# Main program                                                                 #\n################################################################################\n################################################################################\n################################################################################\n# Initialization                                                               #\n################################################################################\n# Set initial variables\nbadoption=0\nSourcePath=\"\/home\/dboth\/\"\nTargetPath=\"\/home\/dboth\/\"\n# TargetPath=\"\/Test\/home\/dboth\/\"\nerror=0\ngpl=0\nRemoteHostName=\"vgr3\"\nnooption=1\nOK=0\nSyncIt=0\nTestMode=0\nThisHost=`hostname | awk -F. '{print $1}'`\nTimeStamp=\"TimeStamp\"\nverbose=0\nversion=2.4.0\n\n################################################################################\n# Process the input options                                                    #\n################################################################################\n# Get the options\nwhile getopts \":ghstvV\" option; do\n   case $option in\n      g) # display GPL license text\n         nooption=0\n         gpl\n         Quit\n         ;;\n      h) # display help\n         nooption=0\n         help\n         Quit\n         ;;\n      s) # Perform the sync\n         nooption=0\n         SyncIt=1\n         ;;\n      t) # Test mode\n         nooption=0\n         TestMode=1\n         ;;\n      v) # Set verbose mode\n         nooption=0\n         verbose=1\n         ;;\n      V) # Print Version number\n         echo \"rsbu Version $version\"\n         Quit\n         ;;\n     \\?) # incorrect option\n         nooption=0\n         badoption=1\n         ;;\n   esac\ndone\n\nif &#91; $nooption = 1 ]\n   then\n   echo \"ERROR: No option entered. You must enter at least one valid option.\"\n   help\n   verbose=1\n   error=\"ID10T\"\n   Quit\nfi\n\nif &#91; $badoption = 1 ]\nthen\n   echo \"ERROR: Invalid option\"\n   help\n   verbose=1\n   error=\"ID10T\"\n   Quit\nfi\n\n\n################################################################################\n# Do the sync                                                                  #\n################################################################################\n\nif &#91; $SyncIt = 1 ]\n   then\n   # This is the normal command that excludes a large number of cache and hidden files.\n   # rsync -aH --exclude=\"*cache\" --exclude=\".*\" -e ssh $SourcePath $RemoteHostName:$TargetPath\n   # This is the copy everything command.\n   rsync -aH --progress -e ssh $SourcePath $RemoteHostName:$TargetPath\nfi\n################################################################################\n\nQuit<\/code><\/pre>\n\n\n\n<p>You can copy this program from here, but I hope to get it added to my downloads page soon. It&#8217;s fairly self-explanatory and the comments, plus the article, <a href=\"https:\/\/www.both.org\/?p=4647\" data-type=\"link\" data-id=\"https:\/\/www.both.org\/?p=4647\" target=\"_blank\" rel=\"noreferrer noopener\">Using rsync for Backup<\/a>, describing how rsync works, should help you understand the code. <\/p>\n\n\n\n<p>The best way to use this program is to set up a <a href=\"https:\/\/www.both.org\/?p=6355\" data-type=\"link\" data-id=\"https:\/\/www.both.org\/?p=6355\" target=\"_blank\" rel=\"noreferrer noopener\">public\/private keypair<\/a> (PPKP) on your source computer, my main workstation for me, and copy the public key to the target laptop. That is a more secure method of granting yourself access to the remote host than using a password.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">It&#8217;s not done yet<\/h2>\n\n\n\n<p>I&#8217;ve used this program for a few years, but I think there are a couple changes I could make to it. See if you can find them. Send us an email to open@both.org to let us know what you&#8217;ve found that can be improved.<\/p>\n\n\n\n<p>Enjoy!<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tomorrow, Saturday as I write this, we&#8217;ll be heading to Atlantic Beach, our current favorite. By then time you read it, we&#8217;ll be there enjoying the amazing views including the one in the picture above. We do this every year. <\/p>\n<p>To make my computing life as seamless as possible, I take my laptop. I always sync my home directory from my primary workstation to my laptop, named Voyager3 or vgr3 for short.<\/p>\n","protected":false},"author":2,"featured_media":6605,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[100,407,5,556,555],"tags":[151,152,350],"class_list":["post-7457","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line","category-file-management","category-linux","category-rsync","category-synchronization","tag-bash","tag-programming","tag-rsync"],"modified_by":"David Both","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/7457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7457"}],"version-history":[{"count":17,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/7457\/revisions"}],"predecessor-version":[{"id":7510,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/7457\/revisions\/7510"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/6605"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}