{"id":881,"date":"2021-08-02T12:00:00","date_gmt":"2021-08-02T19:00:00","guid":{"rendered":"https:\/\/letsbuildroboticswithshadow8472.com\/?p=881"},"modified":"2021-08-02T02:56:32","modified_gmt":"2021-08-02T09:56:32","slug":"a-self-guided-rsync-lesson","status":"publish","type":"post","link":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/2021\/08\/02\/a-self-guided-rsync-lesson\/","title":{"rendered":"A Self-Guided Rsync Lesson"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Good Morning from my Robotics Lab! This is Shadow_8472, and today I am following up on last week\u2019s topic and actually bouncing the game Kerbal Space Program (KSP) back and forth across a couple computers. Let\u2019s get started!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">KSP is a rocket simulator. Rsync is an advanced copy tool. I don\u2019t understand rsync well enough to use it to its full potential, but this week I\u2019m answering three questions in order: 1. Is the project possible? 2. Is the project feasible? 3. Is the project optimizable?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The goal is a smooth transition from one computer to another. When I need to move, I just save\/quit my game, move to the other computer, and start\/continue playing. To do this, I\u2019m copying them to a network share they both have mounted, as a third workstation would make for a messy network trying to move it around ad-hawk.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Possibility<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The main goal here is to get my game running on a different computer, regardless of how ugly the process looks or how long it takes, and ugly it looked and long it took! It\u2019s understandable though. First time moving everything will be from scratch, but after that some noticeable speed up should take place because it should only need to copy the changes between files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Besides taking longer than I\u2019d consider feasible, my game also crashed, locking up Derpy, a workstation I want to play on. The window dressing appeared, but I coldn\u2019t move my mouse or bring up a TTY terminal with CTRL+ALT+&lt;Function keys 1-6&gt;. I had an existing SSH (Secure Shell) connection, and the <strong>top<\/strong> command told me KSP was trying to run, even though I kept trying to shut it down with <strong>kill<\/strong>, even with <strong>sudo<\/strong>. I wasn\u2019t even given an error. I stumbled across using a -9 flag for <strong>kill -9<\/strong>. That worked, but I have yet to understand why. Presumably it\u2019s a little more strongly worded way to stop a program.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My exploration an hour or so later was interrupted by an unexpected success. My game launched, I took a rocket to orbit, confirmed it had enough dv to complete its mission, and I saved and quit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Is the project possible? YES!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Feasibility<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The next step was to go back and forth a few times. In my previous step, I had difficulty finding my game ended up inside my existing game directory instead of syncing to it. I did the same thing again my first attempt trying to retrieve it from Derpy, and it took just as long as the first time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My second attempt started with a successful synchronization from Derpy to the network share with the inclusion of the \u2013<strong>delete<\/strong> flag in case a file is ever removed. I errered on the side of caution and made a copy of my KSP directory inside another directory I called KSPLand. Good thing I did. The way I set up <strong>rsync<\/strong>, the second phase of copying wiped out my backup and stuffed the game directly into KSPLand instead of KSPLand\/Kerbal\\ Space\\ Program\/. I\u2019m attributing this to oversight to trailing slashes at the end of file paths. I would have said I just had a lack of caution, but at least I didn\u2019t wipe out my other games!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Attempt 2.1 went much more smoothly. I compared the exact commands and eliminated the offending slash. I briefly got confused looking through my real game directory and saw one of those recursive copies. This back and forth is mentally exhausting, but it eventually went through.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Rsync Sandbox<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">At this point, I backed out and made a directory where I can practice rsync without it taking half an hour to reset. In it, I made two directories representing my two workstations. In each of those, I made a<strong> notKSP<\/strong> directory with files named after the numbers 1-10 as well as an \u201cinnocent\u201d game directory I didn\u2019t want messed with.I lined up a dozen possible variations controlling for my file path ending in <strong>path<\/strong><strong>\/notKSP<\/strong> is followed by nothing, a <strong>\/<\/strong>, or <strong>\/*<\/strong> as well as my destination\u2019s <strong>path<\/strong>, <strong>path\/<\/strong>, <strong>path\/notKSP<\/strong>, and <strong>path\/notKSP\/<\/strong>. I made a chart by using the \u2013<strong>dry run<\/strong> flag. About half of them appeared to work, but to my surprise, the actual runs didn\u2019t match up.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All my source <strong>path\/notKSP\/*<\/strong> got the data over, but nothing was ever deleted. Also, trailing \/\u2019s on the destination directory didn\u2019t affect my results. The frustrating part is that I had four commands (two if I ignore destination trailing \/\u2019s) give me exactly what I want, and they\u2019re each a single \/ each away from an unsatisfactory command: <strong>rsync -avh &#8211;delete source\/notKSP\/ destination\/ <\/strong>will add <strong>notKSP<\/strong> to <strong>destination<\/strong> and make sure it\u2019s the same while <strong>rsync -avh &#8211;delete source\/notKSP destination\/<\/strong> will make sure the final directory in <strong>destination\/<\/strong> contains <strong>notKSP<\/strong> and nothing else.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In my opinion, the safest form of using rsync is <strong>rsync -avh &#8211;delete source\/notKSP\/ destination\/notKSP\/<\/strong> because if I mess it up and forget the trailing \/, I end up with Russian nesting directories and have to fish a freshly created copy out of the directory it was supposed to update. Furthermore, tab to complete prefers to add those trailing \/ characters [unless an extended directory name is present] and I can specify an alternate directory name for the destination should I choose as I discovered while conducting another test in my rsync sandbox.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Feasibility Cont.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For how useful the &#8211;delete flag is for rsync, it oddly doesn\u2019t have a single-character shortcut. Otherwise, I would have written about implementing it here. There exists a &#8211;del alias, but I\u2019ll pass for now.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With a properly calibrated rsync command, I ran a dry-run to the network share from my tower to the network share. Where I previously had a wall of text detailing all game files being compared, I now only had a few files \u2013many of which were deleting a test game I had purposely planted for later deletion\u2013 totaling to a mere 1.69 megabytes as opposed to the 3 gigabytes of the full game. Even over Wi-Fi, I was done in seconds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Is the project feasible? YES!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Optimizeability<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As long as the possibility remains that a single character can blow a hand-entered command, I won\u2019t be comfortable. The plan from here is to curate a set of four commands and plant them in scripts so I don\u2019t have to retype them each time. One thing is for sure: I\u2019ll be keeping the container directories until I have my scripts working.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019ll probably set each one up in a script and use the appropriate one when I need it. A more complex script might automatically pull any changes from the NAS when I start and push them when I\u2019m done. Once feature creep sets in, I might as well add checks for if the share is down, or if I even need to sync at all. It might even be useful to add a hidden file next to the directory in the share to track who has the game open and error out if I try to open it twice. But then again, those are all dreams. I\u2019d only go to that extent if\/when I give the same treatment to my other entries in my offline\/LAN compatible Steam library.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Is the project optimizable? The sky\u2019s the limit, and I don\u2019t have a rocket.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Takeaway<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As I worked, I learned a bit more about the command line. For example, I discovered how much easier it is working with multiple terminals in the same window. I also learned that <strong>ls<\/strong> will let you peer into multiple directories at once. When a directory is deleted and a backup restored, the normally useless command <strong>cd .<\/strong> will update your terminal from trying to look at the deleted directory to the new one. I was able to work on my rsync commands in one terminal, view results in another, and use a third one to reset between trials. With a little working, I got my two accessory terminals down to a single line each with a little help from the <strong>&amp;&amp;<\/strong> operator to run multiple commands at once.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final Question<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">While working on the verification step, I was running out of time to post and declared victory a little prematurely. I had trouble with my rsync NAS to Derpy dry run looking like a full loadout. Something I did goofed the metadata. Have you ever declared victory early?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Good Morning from my Robotics Lab! This is Shadow_8472, and today I am following up on last week\u2019s topic and actually bouncing the game Kerbal Space Program (KSP) back and forth across a couple computers. Let\u2019s get started! Project Introduction KSP is a rocket simulator. Rsync is an advanced copy tool. I don\u2019t understand rsync &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/2021\/08\/02\/a-self-guided-rsync-lesson\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A Self-Guided Rsync Lesson&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-881","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts\/881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/comments?post=881"}],"version-history":[{"count":1,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts\/881\/revisions"}],"predecessor-version":[{"id":882,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts\/881\/revisions\/882"}],"wp:attachment":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/media?parent=881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/categories?post=881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/tags?post=881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}