<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Rsync on blog.iankulin.com</title><link>https://blog.iankulin.com/tags/rsync/</link><description>Recent content in Rsync on blog.iankulin.com</description><generator>Hugo</generator><language>en-AU</language><lastBuildDate>Mon, 30 Sep 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://blog.iankulin.com/tags/rsync/index.xml" rel="self" type="application/rss+xml"/><item><title>rsync between Synology NAS</title><link>https://blog.iankulin.com/rsync-between-synology-nas/</link><pubDate>Mon, 30 Sep 2024 00:00:00 +0000</pubDate><guid>https://blog.iankulin.com/rsync-between-synology-nas/</guid><description>&lt;p&gt;A while ago, I devised a complicated system where I could drop files in a web interface running on an LXD container and the files would then magically appear in a directory on a remote NAS in the morning. It turned out to not be very robust, and I gave up on it after a while.&lt;/p&gt;
&lt;p&gt;Also, really there should be no need for it - underneath, it was just using &lt;code&gt;rsync&lt;/code&gt; to move the files, so why not just do that direct from one NAS to another? Well, mainly because my NASs are all Synology - which I love, and they&amp;rsquo;ve been great, but in an effort to make them usable by muggles, Synology tend to somewhat complicate things for Linux command line wizards.&lt;/p&gt;
&lt;p&gt;It turns out to be totally possible to command line &lt;code&gt;rsync&lt;/code&gt;, including doing it over Tailscale, but there&amp;rsquo;s a couple of gotchas along the way.&lt;/p&gt;
&lt;h3 id="rsync-the-synology-way"&gt;rsync the Synology way&lt;/h3&gt;
&lt;p&gt;A reasonable question would be why didn&amp;rsquo;t I use the Synology rsync user interface to do all this - it&amp;rsquo;s right there in Control Panel / File Services? I did actually look at doing that, but after five minutes I couldn&amp;rsquo;t figure it out, so yeah na. It&amp;rsquo;s the command line for me.&lt;/p&gt;
&lt;h3 id="steps"&gt;Steps&lt;/h3&gt;
&lt;p&gt;The plan for the rest of this post is just to run through, in approximate order, the steps you&amp;rsquo;ll need to take to get &lt;code&gt;rsync&lt;/code&gt; working from the command line to sync files between two synology NASs. It&amp;rsquo;s probably also helpful between a real system and a Synology NAS. I&amp;rsquo;m going to talk about the &amp;rsquo;local&amp;rsquo; NAS (where we&amp;rsquo;ll be running the rsync command) and &amp;lsquo;remote&amp;rsquo; one. This is just for convenience - you might have two local or two remote NASs - I don&amp;rsquo;t judge. I&amp;rsquo;m just calling mine &amp;rsquo;local&amp;rsquo; and &amp;lsquo;remote&amp;rsquo; for this post that so you know which device I&amp;rsquo;m talking about.&lt;/p&gt;
&lt;h4 id="ssh"&gt;ssh&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;rsync&lt;/code&gt; works over an ssh connection, so you need to be able to ssh from one NAS to another without entering a password first. To test it, ssh into the local NAS, then without logging out, ssh into the remote NAS from the local one. If that works without asking for a password you&amp;rsquo;ve completed this step and can just ctrl-D to drop back to the local NAS.&lt;/p&gt;
&lt;p&gt;If the issue is that it asked for a password, that just means you need to install your public ssh keys on the remote. I usually do this with the &lt;code&gt;ssh-copy-id&lt;/code&gt; command on regular Linux, Mac and BSD systems, but that&amp;rsquo;s not available at the Synology command line so we&amp;rsquo;ll have to do it the old fashioned way.&lt;/p&gt;
&lt;p&gt;Anything to do with ssh is stored in a hidden directory, &lt;code&gt;.ssh&lt;/code&gt; in a user&amp;rsquo;s home directory. For example you can check you&amp;rsquo;ve got public keys with:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ls -la ~/.ssh/id_rsa.pub
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;These are the keys you want to add to the remote NASs authorised keys, so we&amp;rsquo;ll use ssh (with a password) to add them to the end of that file:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ssh &amp;lt;user&amp;gt;@&amp;lt;remote NAS address&amp;gt; &amp;#39;cat &amp;gt;&amp;gt; ~/.ssh/authorized_keys&amp;#39; &amp;lt; ~/.ssh/id_rsa.pub
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You need to substitute your remote NASs username and address, so mayby it would look like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ssh nas1_admin@83.78.2.105 &amp;#39;cat &amp;gt;&amp;gt; ~/.ssh/authorized_keys&amp;#39; &amp;lt; ~/.ssh/id_rsa.pub
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When you execute this, it will ask for the remote password, but once it&amp;rsquo;s worked you should be able to ssh in and it allows that without using a password.&lt;/p&gt;
&lt;h4 id="tailscale-out"&gt;Tailscale out&lt;/h4&gt;
&lt;p&gt;Perhaps you didn&amp;rsquo;t get as far as needing the ssh password, because when you tried to ssh to the remote, ssh didn&amp;rsquo;t even recognise the domain. If you are using Tailscale to connect your devices (which I recommend) then there are two tricks needed.&lt;/p&gt;
&lt;p&gt;Trick one is to get around the fact that since DSM 7, Synology have prevented (for good security reasons) external packages from making outbound connections. So you&amp;rsquo;ll be able to use Tailscale to access the Synology web interface, or even ssh &lt;em&gt;into&lt;/em&gt; it, but you won&amp;rsquo;t be able to ssh &lt;em&gt;out&lt;/em&gt; of it. When I first discovered this, I was running &lt;code&gt;ip a&lt;/code&gt; at the command line in the local NAS and noticed that the tailscale IP was not even listed - it was as if Tailscale wasn&amp;rsquo;t running, but I knew it was since I had ssh&amp;rsquo;d in with the Tailscale address.&lt;/p&gt;
&lt;p&gt;Tailscale have a fix for &lt;a href="https://tailscale.com/kb/1131/synology#enable-outbound-connections"&gt;enabling outbound connections via Tailscale on Synology&lt;/a&gt;, you need to run a thing on reboot to enable the TUN.&lt;/p&gt;
&lt;p&gt;Trick two is that even after you&amp;rsquo;ve done that and rebooted and can see the tailscale interface when you run &lt;code&gt;ip a&lt;/code&gt;, you still won&amp;rsquo;t be able to use the Tailscale &amp;lsquo;magic&amp;rsquo; DNS but will have to use the Tailscale IP address for the remote when you ssh (and later rsync) to it. So I can&amp;rsquo;t use:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ssh nas1_admin@NAS-01&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;as I would normally from my laptop, I have to use &lt;code&gt;ssh nas1_admin@104.43.22.181&lt;/code&gt; If you are not sure of the Tailscale IP for your remote, have a look at your &lt;a href="https://login.tailscale.com/admin/machines"&gt;machines list&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id="turn-rsync-on"&gt;Turn rsync on&lt;/h4&gt;
&lt;p&gt;Via the web interface on both Synologys, you&amp;rsquo;ll need to enable rsync. The setting is in &lt;code&gt;Control Panel | File Services | rsync&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://blog.iankulin.com/images/screen-shot-2024-08-25-at-1.56.57-pm.png"&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2024-08-25-at-1.56.57-pm.png" width="900" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Leave the port as 22 and don&amp;rsquo;t bother with the other settings, but do hit &lt;code&gt;Apply&lt;/code&gt; at the bottom to save the change.&lt;/p&gt;
&lt;h4 id="give-it-a-try"&gt;Give it a try&lt;/h4&gt;
&lt;p&gt;We&amp;rsquo;re now at the stage where you should be able to ssh into the remote NAS from the local one without being asked for a password, and rsync is turned on both ends, so in theory, you should be able to do something like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync -rvitn /volume1/ nas1_admin@104.43.22.181:/volume1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I&amp;rsquo;m not going to go into all the flags for rsync (the internet has plenty of good guides for that) except to say that the &amp;rsquo;n&amp;rsquo; on the end of the flags in the command above means that no files will actually be moved, it will do a &amp;lsquo;dry run&amp;rsquo; and tell you what it would have done if you let it.&lt;/p&gt;
&lt;p&gt;Note that if you have a jazillion files, this could take a while, you might be better to limit it to a smaller sub directory such as &lt;code&gt;/volume1/media/music/napster/Metallica&lt;/code&gt;/&lt;/p&gt;
&lt;img src="https://blog.iankulin.com/images/yo-dawg-heard-you.jpg" width="497" alt=""&gt;
&lt;p&gt;The other bit of free rsync advice I&amp;rsquo;ll give you is to look carefully at the source and destination directories in the command above. The source sub directory has a trailing &amp;lsquo;/&amp;rsquo;, the destination does not. If you mess this up you&amp;rsquo;ll be making directories inside your directories dawg.&lt;/p&gt;
&lt;p&gt;In theory once you&amp;rsquo;re at this point, everything should work. But here&amp;rsquo;s a couple of other bumps / thoughts.&lt;/p&gt;
&lt;h4 id="eadir"&gt;@eaDir&lt;/h4&gt;
&lt;p&gt;Synology has a bunch of hidden directories with metadata stuff. My advice is don&amp;rsquo;t mess with them, but also don&amp;rsquo;t sync them over either. Tell rsync to ignore them. Same for the recycle bin.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync -rvitn --exclude &amp;#39;*@eaDir*&amp;#39; --exclude &amp;#39;#recycle*&amp;#39; /volume1/ nas1_admin@104.43.22.181:/volume1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="permissions"&gt;Permissions&lt;/h3&gt;
&lt;p&gt;The user that you&amp;rsquo;re ssh&amp;rsquo;ing with needs to have permissions to all the places you are rsync&amp;rsquo;ing files to. Even though I&amp;rsquo;ve only ever had one user for each of my Synology NAS&amp;rsquo;s, and everything has been done by that one user either through the web GUI or command line, the files and directories on my NAS have a mixture of owners (my user and root) and permissions. Someone smarter than me could probably figure out why - and if your NAS has to include files from multiple users etc, you are going to need to do that. Because I like sledgehammers, all I did was ssh into the remote and:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sudo chown -R nas1_admin:users /volume1/media
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sudo chmod -R 775 /volume1/media
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id="throttling-bandwidth"&gt;Throttling bandwidth&lt;/h4&gt;
&lt;p&gt;If I saturate the downlink at my remote site while I&amp;rsquo;m rsync-ing a bunch of files, the users there will be unhappy when they can&amp;rsquo;t stream video reliability or if they&amp;rsquo;re getting killed in online games due to lag.&lt;/p&gt;
&lt;p&gt;rsync has a flag for that. If we want to limit the transfer bandwidth to 500KB it could look like:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync -rvitn --bwlimit=500 --exclude &amp;#39;*@eaDir*&amp;#39; --exclude &amp;#39;#recycle*&amp;#39; /volume1/ nas1_admin@104.43.22.181:/volume1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id="get-destructive"&gt;Get destructive&lt;/h4&gt;
&lt;p&gt;If you only want to sync the files one way from your local to remote, then we can add a flag that will delete any files on the remote machine that are not present on the local one. Obviously use with care, and run with the -n flag first to see what&amp;rsquo;s going to get chopped.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync -rvitn --bwlimit=500 --exclude &amp;#39;*@eaDir*&amp;#39; --exclude &amp;#39;#recycle*&amp;#39; /volume1/ nas1_admin@104.43.22.181:/volume1 --del
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id="do-something-else"&gt;Do something else&lt;/h4&gt;
&lt;p&gt;The first few times you do this, it will be exciting watching the terminal window as rsync carefully checks for each file and directory and copies them over as needed, and it will also be helpful to see what errors might pop up so you can sort them out.&lt;/p&gt;
&lt;p&gt;Eventually though, it will be so routine and error free you&amp;rsquo;d rather do something else, so you&amp;rsquo;ll wander off and leave it, then curse when you return to find your laptop turned itself off due to inactivity and wrecked the rsync. Don&amp;rsquo;t panic, rsync is robust and will pick right up next time you run it without damaging any files, but you might also consider doing it all on remote control.&lt;/p&gt;
&lt;p&gt;On the local NAS, create a file called &lt;code&gt;sync-media.sh&lt;/code&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#5e81ac;font-style:italic"&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;nohup rsync -rvitn --bwlimit&lt;span style="color:#81a1c1"&gt;=&lt;/span&gt;&lt;span style="color:#b48ead"&gt;500&lt;/span&gt; --exclude &lt;span style="color:#a3be8c"&gt;&amp;#39;*@eaDir*&amp;#39;&lt;/span&gt; --exclude &lt;span style="color:#a3be8c"&gt;&amp;#39;#recycle*&amp;#39;&lt;/span&gt; /volume1/ nas1_admin@104.43.22.181:/volume1 &amp;gt; sync_media.log 2&amp;gt;&lt;span style="color:#eceff4"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color:#b48ead"&gt;1&lt;/span&gt; &lt;span style="color:#eceff4"&gt;&amp;amp;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Make it executable:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chmod +x sync_media.sh
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Once you run it &lt;code&gt;./sync-media.sh&lt;/code&gt; you can log off and let it do it&amp;rsquo;s thing.&lt;/p&gt;</description></item><item><title>rsync episode IV - a sudo hope</title><link>https://blog.iankulin.com/rsync-episode-iv-a-sudo-hope/</link><pubDate>Thu, 30 Mar 2023 00:00:00 +0000</pubDate><guid>https://blog.iankulin.com/rsync-episode-iv-a-sudo-hope/</guid><description>&lt;p&gt;With all those earlier rsync bumps out of the way, I was ready to try my first rsync backup at the command line to sync my movies directory on the NAS to a (NTFS formatted) USB drive plugged into the same NAS. This is to be one of the simplest since there&amp;rsquo;s no remote server involved, just copying from mount point directory to another - so no drama with remote permissions.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s a lot of files involved, and I knew from running the dry run that there would be a lot of output. I could see a few error messages, but each of the file copies was taking a while so I was confident they, at least, were working. If you missed the last episode, here&amp;rsquo;s where I landed for this rsync command.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync -avi --exclude &amp;#39;*@eaDir*&amp;#39; /volume1/media/video/Movies/ /volumeUSB1/usbshare/media/video/Movies --del
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Before I worried about the error messages, I had a look to see if the files had been copied correctly, but they had not. Even though each file was taking about the right amount of time to copy, the new files were not making it to the destination directories. Nor did they seem to be anywhere else. So I guess go back to the error messages and try to understand them. Here&amp;rsquo;s a &lt;em&gt;very&lt;/em&gt; condensed selection of the output.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync: failed to set times on &amp;#34;/volumeUSB1/usbshare/media/video/Movies/Jungle Book (1942)&amp;#34;: Operation not permitted (1)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;...
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;gt;f+++++++++ Jungle Book (1942)/Jungle Book (1942).mkv
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;gt;f+++++++++ Jungle Book (1942)/trailer.mp4
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;...
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync: mkstemp &amp;#34;/volumeUSB1/usbshare/media/video/Movies/Jungle Book (1942)/.Jungle Book (1942).mkv.Wd141R&amp;#34; failed: Operation not permitted (1)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync: mkstemp &amp;#34;/volumeUSB1/usbshare/media/video/Movies/Jungle Book (1942)/.trailer.mp4.TNu7UC&amp;#34; failed: Operation not permitted (1)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This log is from one of my later attempts. This video was new on the NAS so an earlier running of the rsync would have had some more lines about creating the directory on the USB - and I had a through the file browser in the NAS. The correct directory had been created, but there were no files in it.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s have a look at this output a bit at a time:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync: failed to set times on &amp;#34;/volumeUSB1/usbshare/media/video/Movies/Jungle Book (1942)&amp;#34;: Operation not permitted (1)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;rsync is trying to update the date/time of the destination folder to match the source one - something similar to the &lt;code&gt;touch&lt;/code&gt; command. &lt;code&gt;not permitted&lt;/code&gt; sounds like a &lt;a href="https://blog.iankulin.com/could-it-be-a-permissions-problem/"&gt;permissions issue&lt;/a&gt;. There was one of these messages for every directory and they were all near the start of the log.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;gt;f+++++++++ Jungle Book (1942)/Jungle Book (1942).mkv
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;gt;f+++++++++ Jungle Book (1942)/trailer.mp4
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;These are not errors, but encouraging output. The code at the beginning says what&amp;rsquo;s going on - they are files, and are being copied from the source to the destination. These showed up for every file that was in the source but not the destination, and the times for the file copies felt about right - the .mkv file took a while, the trailer was quick. These messages were all together in the middle of the log.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync: mkstemp &amp;#34;/volumeUSB1/usbshare/media/video/Movies/Jungle Book (1942)/.Jungle Book (1942).mkv.Wd141R&amp;#34; failed: Operation not permitted (1)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync: mkstemp &amp;#34;/volumeUSB1/usbshare/media/video/Movies/Jungle Book (1942)/.trailer.mp4.TNu7UC&amp;#34; failed: Operation not permitted (1)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;[mkstemp](https://man7.org/linux/man-pages/man3/mkstemp.3.html)&lt;/code&gt; is a command for creating a temporary file. It&amp;rsquo;s common in operating systems to use a hidden temporary file when transferring a file - you save into the temp file then rename it when its successfully completed. I&amp;rsquo;m guessing that&amp;rsquo;s what&amp;rsquo;s happening here, and it&amp;rsquo;s failing for permissions reasons. What I don&amp;rsquo;t understand is why they would all be grouped together at the end of the log instead of back next to each individual copy.&lt;/p&gt;
&lt;p&gt;But anyway, this is clearly a permissions problem. I can easily check this just by trying the copy manually. I&amp;rsquo;m still logged in as the same user who executed the &lt;code&gt;rsync&lt;/code&gt; command so the &lt;code&gt;cp&lt;/code&gt; will have the same rights etc and so should also fail&amp;hellip;&lt;/p&gt;
&lt;p&gt;No - this copy worked perfectly. No error message, and when I used the NAS filebrowser, the new file had correctly copied onto the USB drive.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cp /volume1/media/video/Movies/&amp;#39;Jungle Book (1942)&amp;#39;/&amp;#39;Jungle Book (1942).mkv&amp;#39; /volumeUSB1/usbshare/media/video/Movies/&amp;#39;Jungle Book (1942)&amp;#39;/
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So somehow &lt;code&gt;rsync&lt;/code&gt; is running with lower permissions than &lt;code&gt;cp&lt;/code&gt; when executed by the same user? Well, (grasping at straws now) what if I &lt;code&gt;sudo&lt;/code&gt; it? I tried that, and (1) there&amp;rsquo;s no &lt;em&gt;set times&lt;/em&gt; error, (2) all the file copies worked, and (3) no &lt;em&gt;mkstemp&lt;/em&gt; errors.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sudo rsync -avi --exclude &amp;#39;*@eaDir*&amp;#39; /volume1/media/video/Movies/ /volumeUSB1/usbshare/media/video/Movies --del
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I did notice one other difference, there was lots of &amp;lsquo;o&amp;rsquo; in the itemize changes output:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;.d..tpo.... Jungle Book (1942)/
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;gt;f..tpo.... Jungle Book (1942)/Jungle Book (1942).mkv
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;gt;f+++++++++ Jungle Book (1942)/trailer.mp4
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;From the &lt;a href="https://download.samba.org/pub/rsync/rsync.1#opt--itemize-changes"&gt;man page&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;.d..tpo....&lt;/code&gt; - not being copied, it&amp;rsquo;s a directory, modification time is different and is being updated, permissions are different and are being updated, the owner is different and is being updated&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;gt;f..tpo....&lt;/code&gt; - is being copied to destination, it&amp;rsquo;s a file, modification time is different and is being updated, permissions are different and are being updated, the owner is different and is being updated&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;gt;f+++++++++&lt;/code&gt; - is being copied to destination, it&amp;rsquo;s a file, everything is being newly created so will be the same as the source&lt;/p&gt;
&lt;p&gt;So that&amp;rsquo;s a major step forward, the files are syncing correctly, and if I rerun the rsync and haven&amp;rsquo;t made any changes to the source files, it zips through. I do notice it is still updating the permissions and owner each time. This doesn&amp;rsquo;t produce an error message, but since it thinks they need done every run it suggests it is not happening correctly.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s possible the owner/permissions issue is related to the USB drive being NTFS formatted. It&amp;rsquo;s also possible I can get rsync to stop trying to change those since they are not important in this context. the &lt;code&gt;-a&lt;/code&gt; flag (short for archive) is a shortcut that pulls in a number of other flags. Perhaps I can just pick the ones I need and eliminate the owner and permissions ones.&lt;/p&gt;
&lt;p&gt;Having to sudo to get this to work does not seem like a great solution - presumably this will come back to bite me when I try and automate it. So there is still some figuring out to do, but at least one step of my backup is down now.&lt;/p&gt;</description></item><item><title>rsync / Synology / @eaDir</title><link>https://blog.iankulin.com/rsync-synology-eadir/</link><pubDate>Tue, 28 Mar 2023 00:00:00 +0000</pubDate><guid>https://blog.iankulin.com/rsync-synology-eadir/</guid><description>&lt;p&gt;The reason I&amp;rsquo;ve been figuring out rsync is to setup my backup strategy. Eventually this will partly be managed with scheduled tasks (ie cron jobs) running rsync. I wanted the SSH in and try this out, since I didn&amp;rsquo;t know some basic things like the mount points of the shares.&lt;/p&gt;
&lt;h3 id="mount-points"&gt;Mount points&lt;/h3&gt;
&lt;p&gt;My first issue was to find the paths to all my data. This turned out not to be a drama. Each of the volumes you create when the NAS is set up are just in the root directory. This includes any USB drives plugged in.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-03-25-at-8.08.10-pm.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Inside each of those &lt;em&gt;volumes&lt;/em&gt; are any &lt;em&gt;shares&lt;/em&gt; you&amp;rsquo;ve created. At the moment I want to rsync my movies which are in a &amp;lsquo;media&amp;rsquo; share on volume1 to the usb drive, so the directories I&amp;rsquo;ll be using are:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;/volume1/media/video/Movies/&lt;/code&gt;&lt;br&gt;
&lt;code&gt;/volumeUSB1/usbshare/media/video/Movies&lt;/code&gt;&lt;/p&gt;
&lt;h3 id="rsync-attempt"&gt;rsync attempt&lt;/h3&gt;
&lt;p&gt;rsync has a cool feature whereby you can do a &amp;lsquo;dry run&amp;rsquo; where it goes through the motions of the command you&amp;rsquo;ve given it, but doesn&amp;rsquo;t change any files. If you combine this with the verbose output, you can clearly see what it&amp;rsquo;s going to do before you let it start changing things. That&amp;rsquo;s an especially good idea when you&amp;rsquo;re dealing with large amounts of data, so my first pass at this included the -n option.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync -avin /volume1/media/video/Movies/ /volumeUSB1/usbshare/media/video/Movies --del
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The situation with these two lots of data is that I&amp;rsquo;ve copied my media off the USB drive onto the NAS, then when I installed Jellyfin to access it, I discovered lots of misnamed items (had the years incorrect mostly) and I&amp;rsquo;ve been combining some directories, and renaming others and so on. So I expected this first run or rsync to pull up a heap of changes to make, which it did - thousands of lines of them.&lt;/p&gt;
&lt;p&gt;I noticed a lot of them included this weird directory that I didn&amp;rsquo;t recognise.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;gt;f+++++++++ @eaDir/Tora Tora Tora (1970 PG)@SynoEAStream
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;gt;f+++++++++ @eaDir/Tora Tora Tora (1970 PG)@SynoResource
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I&amp;rsquo;ve since learned it might be extended attributes, people started noticing it around the introduction of DSM7. &lt;a href="https://tech.webit.nu/synology-nas-those-eadir-folders/"&gt;I don&amp;rsquo;t seem to be the only user who hates&lt;/a&gt; Synology messing with my data. There&amp;rsquo;s some consensus they are created by the indexing service (which I&amp;rsquo;ve turned off as much as is possible in the GUI) and when the &lt;a href="https://www.reddit.com/r/synology/comments/exh5ho/preventing_eadir_from_being_created/"&gt;drives are externally mounted&lt;/a&gt; - which of course I have been doing quite a bit while moving things around.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ll tackle removing them all and trying to prevent their reoccurence another day, but for the moment, I&amp;rsquo;ll just tell rsync to ignore them using the &lt;code&gt;--exclude&lt;/code&gt; option.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync -avin --exclude &amp;#39;*@eaDir*&amp;#39; /volume1/media/video/Movies/ /volumeUSB1/usbshare/media/video/Movies --del
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>rsync basics</title><link>https://blog.iankulin.com/rsync-basics/</link><pubDate>Sun, 26 Mar 2023 00:00:00 +0000</pubDate><guid>https://blog.iankulin.com/rsync-basics/</guid><description>&lt;p&gt;I&amp;rsquo;ve started down the path of improved storage management, including embracing the &lt;a href="https://www.backblaze.com/blog/the-3-2-1-backup-strategy/"&gt;3-2-1&lt;/a&gt; mantra. I&amp;rsquo;ve settled on a RAID6 NAS for local, mirrored to an off-site NAS, and an offline local USB drive.&lt;/p&gt;
&lt;p&gt;While I&amp;rsquo;ve been setting those up, my services have been live, so files have been changing on my main storage, which I&amp;rsquo;ve then switched to the bigger NAS, and I&amp;rsquo;ve been trying to keep data in sync by remembering what changes have been made where, and manually replicating them. That&amp;rsquo;s not sustainable and not the plan.&lt;/p&gt;
&lt;h3 id="beyond-compare"&gt;Beyond Compare&lt;/h3&gt;
&lt;p&gt;Many years ago, on Windows, I paid for a file/text comparison app called &lt;a href="https://www.scootersoftware.com/features.php"&gt;Beyond Compare&lt;/a&gt; - it says on their website that these are perpetual licences, and I&amp;rsquo;ve had many years of value out of it. I think I bought it about the same time I dabbled in version control thanks to the excellent book Code Complete (&lt;a href="https://www.amazon.com.au/Code-Complete-Steve-McConnell/dp/0735619670"&gt;this link&lt;/a&gt; is to the second version, but I&amp;rsquo;ve had both over the years).&lt;/p&gt;
&lt;p&gt;If you have to do manual syncing jobs between different directories or machines, this is an excellent graphical tool to do that with. I have never tried any other software because it&amp;rsquo;s always just done exactly what I needed with no hassle. Highly recommend.&lt;/p&gt;
&lt;p&gt;However, doing things manually is no way to do backups - you need a setup that runs without human intervention so it actually gets done.&lt;/p&gt;
&lt;h2 id="rsync"&gt;rsync&lt;/h2&gt;
&lt;p&gt;I never fail to be amazed at the substantial but unassuming command line tools from the Linux world, and this is another one. &lt;code&gt;rsync&lt;/code&gt; is perfect for this specific job - of keeping my remote backup in sync with the production storage. Here&amp;rsquo;s a few examples of how it works.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s say I&amp;rsquo;ve got two directories in my home folder called localdir and remotedir. localdir has some files in it and I want them copied to the remotedir. &lt;code&gt;rsync&lt;/code&gt; can do that for us with this command. The &lt;code&gt;-a&lt;/code&gt; flag does a few things, including recursing into directories and preserving some of the file attributes when it copies files. I found if I didn&amp;rsquo;t do this, and just used -&lt;code&gt;r&lt;/code&gt; for the recursion, rsync&amp;rsquo;s system for checking for changes didn&amp;rsquo;t work.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync -a localdir/ remotedir
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-03-25-at-1.13.44-pm.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Okay, that&amp;rsquo;s not impressive, I could have done the same thing with &lt;code&gt;cp&lt;/code&gt; to copy those files. And actually I could do that for my remote backup as well, except there&amp;rsquo;s no point burning up resources for copying identical files on top of each other. Really we just want to copy the files that have changed, or new files that have been added.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s try that by editing &lt;code&gt;file1.txt&lt;/code&gt;, and adding a new &lt;code&gt;file0.txt&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-03-25-at-1.18.57-pm.jpg" alt=""&gt;&lt;/p&gt;
&lt;p&gt;You might be thinking that perhaps rsync really is just copying all the files again. We can add a couple more flags to get rsync to tell us what is getting copied (&lt;code&gt;-v&lt;/code&gt; for verbose, and &lt;code&gt;-i&lt;/code&gt; which gives some output explaining how it decided a file needed copied.&lt;/p&gt;
&lt;p&gt;Without making any changes, let&amp;rsquo;s re-run the rsync with those flags. We shouldn&amp;rsquo;t see any files updated.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-03-25-at-1.24.51-pm.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;So no files transferred, but if we edit a one and change the timestamp on another one, that should trigger a couple of files to be copied.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-03-25-at-1.27.48-pm.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;The optimisation in rsync extends further than just copying the files that have changed, the &lt;a href="https://download.samba.org/pub/rsync/rsync.1"&gt;man page&lt;/a&gt; says &amp;ldquo;&lt;em&gt;It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination.&lt;/em&gt;&amp;rdquo;&lt;/p&gt;
&lt;h3 id="deletions"&gt;Deletions&lt;/h3&gt;
&lt;p&gt;So that covers copying most of the changes in the source, but what about if a local file is deleted, does that propagate to the destination and delete the file there? Naturally, there is also an option for this; simply add &lt;code&gt;--del&lt;/code&gt; to the end of the command:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-03-25-at-3.35.49-pm.jpg" alt=""&gt;&lt;/p&gt;
&lt;h3 id="remote-hosts"&gt;Remote hosts&lt;/h3&gt;
&lt;p&gt;So far, all of these examples have been between directories on a single instance. What about on a remote machine? There&amp;rsquo;s a couple of steps.&lt;/p&gt;
&lt;p&gt;First, the machine where the rsync is being executed must have ssh access to the other machine. This is just the usual ssh setup - &lt;code&gt;ssh-keygen&lt;/code&gt; some keys if you don&amp;rsquo;t have any, then copy them over with &lt;code&gt;ssh-copy-id&lt;/code&gt; and we&amp;rsquo;re ready to go&lt;/p&gt;
&lt;p&gt;The second part is to add an ssh like address to the remote directory. So instead of just&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync -avi localdir/ remotedir --del
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;it will be&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rsync -avi localdir/ ian@192.168.100.33:remotedir --del
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Before I&amp;rsquo;ve run this, I&amp;rsquo;ve sshed in and created the directory &lt;code&gt;remotedir&lt;/code&gt; on the target machine, but then it&amp;rsquo;s simple as&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.iankulin.com/images/screen-shot-2023-03-25-at-5.06.01-pm.jpg" alt=""&gt;&lt;/p&gt;
&lt;h3 id="reading"&gt;Reading&lt;/h3&gt;
&lt;p&gt;To figure all this out, I&amp;rsquo;ve leaned heavily on this tutorial &amp;ldquo;&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories"&gt;How To Use Rsync to Sync Local and Remote Directories&lt;/a&gt;&amp;rdquo; from Digital Ocean, and for the stuff about deleting remote files when they are deleted locally, on &lt;a href="https://askubuntu.com/questions/476041/how-do-i-make-rsync-delete-files-that-have-been-deleted-from-the-source-folder"&gt;this Stack Exchange&lt;/a&gt; question.&lt;/p&gt;
&lt;p&gt;The source of truth, is the surprisingly readable &lt;a href="https://download.samba.org/pub/rsync/rsync.1"&gt;man page&lt;/a&gt;.&lt;/p&gt;</description></item></channel></rss>