<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Angelo Gazzola on Medium]]></title>
        <description><![CDATA[Stories by Angelo Gazzola on Medium]]></description>
        <link>https://medium.com/@nglgzz?source=rss-3c4d384b5dee------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*hl0ZBXarUcrrLoDq22gA-Q.jpeg</url>
            <title>Stories by Angelo Gazzola on Medium</title>
            <link>https://medium.com/@nglgzz?source=rss-3c4d384b5dee------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:58:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nglgzz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A syncing problem]]></title>
            <link>https://medium.com/@nglgzz/a-syncing-problem-ac488f84a619?source=rss-3c4d384b5dee------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac488f84a619</guid>
            <category><![CDATA[rsync]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[filesystem]]></category>
            <dc:creator><![CDATA[Angelo Gazzola]]></dc:creator>
            <pubDate>Fri, 05 Jan 2018 18:48:52 GMT</pubDate>
            <atom:updated>2018-01-05T18:53:25.823Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JggJLMOPdaUrHEl0NM35HQ.jpeg" /></figure><p>As a software developer that works on several projects at once, both at work and on my spare time, keeping my filesystem clean can be quite a challenge. Add to that the fact that I don’t always use the same computer and it gets even more complicated.</p><h3>The problem</h3><p>In the very beginning when I only had my PC I would keep my projects in the “Desktop” while I was working on them, and then move them to “Documents” when they were finished. There were no backups and no version control, partly because I didn’t know what those were, and partly because the projects were so small and I was almost never going back to them, so even if they got lost it was no big deal.</p><p>Eventually I got a laptop and I started using that too for development. I didn’t think too much about it, and used the same system I was using for the PC. Sometimes it would happen that I would go back to see how I did a certain thing on a previous project, and I couldn’t remember where it was, so I had to search on both computers.</p><p>Fast forward to when I started working, it became even more of a problem. I was developing most of the time on my laptop, but sometimes I needed to use my PC to get some things done faster. I was working on the same code from both machines. It would often happen that I forgot where the latest version was, and I either had to check the code on both computers to determine which had the most recent changes, or I continued working on an old version to only realize that when it was too late.</p><h3>The first solution</h3><p>It was around that time that I started learning Git and I got a Raspberry Pi, so I tried to get more organized with the newly acquired tools. I created a repository with all my projects on the Raspberry. Whenever I needed to switch from one computer to the other I would push the changes from one side, and then pull them from the other one.</p><p>That system was a big upgrade from before, first because if something happened to my laptop or PC, I could clone my projects back from the Raspberry; but also because most of the time almost all files on the “projects” folder would be the same between computers.</p><p>This would work perfectly in theory… In practice you have to remember to always push and pull changes, all the files that you add to the repository must be within a certain size limit, if you add a git repository you have to add it as a submodule, and if you move a submodule you have to use git mv<strong> </strong>instead of just mv. This led to quite some time spent on Stack Overflow and reading Git docs.</p><p>After a while I decided to introduce some automation, which consisted in simply pushing changes before shutting down the computer, and pulling them when starting it. It made keeping the repository up to date much easier, but I still needed to push the changes manually if I had both computers on at the same time, and the constraints with file sizes and submodules were still there.</p><h3>In search of a new solution</h3><p>Despite working okay, manually pulling/pushing changes, and solving submodule problems felt like a chore. So a year and a half later, I decided to revisit my solution. Here’s a list of the things I tried, how they work, and why I did or didn’t stick with them.</p><h4>SSHFS</h4><p>From the <a href="https://github.com/libfuse/sshfs">project’s README</a>:</p><blockquote>SSHFS allows you to mount a remote filesystem using SFTP. Most SSH servers support and enable this SFTP access by default, so SSHFS is very simple to use — there’s nothing to do on the server-side.</blockquote><p>Basically I would run sshfs projects pi@192.168.1.106:/path/to/projects and I could access the /path/to/projects folder that is on the Raspberry from my PC, without actually downloading it (at least not all of it).</p><p>This got me super excited. First because there would be no need for syncing, since all changes would happen directly on the Raspberry. But most importantly it was so simple to set up, I would just need to run the command above when starting the PC (either by adding it on my .zshrc file, or by creating a systemd service).</p><p>All the excitement faded away when I tried to find a file in that directory and it took a few minutes to return the results when usually it’s near instant. This can be improved with <a href="https://superuser.com/a/961034">caching</a>, but even then when opening an entire directory on my editor it still felt pretty slow. I think this could work if I was working only locally, or if I had a fast internet connection.</p><p>Another thing to note is that using SSHFS doesn’t provide you any sort of backup. Unlike with syncing, your projects are only on the Raspberry, and if that has a problem your projects are gone.</p><h4>Rsync</h4><p><a href="https://wiki.archlinux.org/index.php/rsync">Rsync</a> is an incremental file transfer tool. It’s like an scp on steroids. It allows you to copy files or folders both locally or remotely, but it can do it at an incredible speed by sending only the diffs of the files that changed. It also offers many options on how to check for files that changed and what to send, but I was very happy with the defaults.</p><p>The only problem I had with it, which makes it very hard to use as a syncing tool, is that it’s a one way tool. In my case I could copy my local files on the Raspberry, but if something changed there, the change wouldn’t propagate to my computer, and it would be overridden the next time I run rsync.</p><h4>Osync</h4><p>This is what I ended up using. From their <a href="https://github.com/deajan/osync">GitHub repository</a> osync is:</p><blockquote>A robust two way (bidirectional) file sync script based on rsync with fault tolerance, ACL support and time control</blockquote><p>As the description says it’s built on top of rsync and it’s bidirectional, which is exactly what I needed. When you run the script once, it just syncs the content of the directory you specify, so you should set up a way to run it periodically.</p><p>I used a <a href="https://wiki.archlinux.org/index.php/Systemd/Timers">systemd timer</a> to execute the script at every boot and after that every 10 minutes. I preferred systemd to cron because it’s installed by default on many Linux distributions, and on systemd I can specify dependencies. In this case I specified that an internet connection is needed to run the script, so it won’t be executed before I connect my laptop to the WiFi.</p><p>The code for the setup can be found in the files below:</p><ul><li><a href="https://github.com/nglgzz/dots/blob/master/dots/.config/systemd/user/projects-sync.timer">systemd/user/projects-sync.timer</a></li><li><a href="https://github.com/nglgzz/dots/blob/master/dots/.config/systemd/user/projects-sync.service">systemd/user/projects-sync.service</a></li><li><a href="https://github.com/nglgzz/dots/blob/master/dots/.config/systemd/sync-projects.sh">systemd/sync-projects.sh</a></li></ul><h3>Conclusion</h3><p>Some lessons learned from this journey are:</p><ul><li><strong>Put your problem into words.</strong> If I knew from the beginning that all I needed was a syncing tool, I would have saved a bunch of time. I only realized that when trying to explain to a friend my setup, and why I was trying to move away from Git.</li><li><strong>The tool you need probably exists.</strong> Once you put your problem into words, try to search and see how other people solved it. It’s very unlikely that you’re the only person in the world having such problem, and if many are having it, there’s probably a tool to deal with it.</li><li><strong>Consider maintenance.</strong> Whether you decide to go with an existing tool, or build your own, consider how much time you will need to spend maintaining it. The last thing you want is something that breaks on you when you most need it and you have no time to fix it. This also applies to configuration.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac488f84a619" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>