Migrating my Knot

In my previous pub I went over the process I went through to set up my own Tangled Knot and the problems I faced. One of those problems stemmed from the fact that I was using my PDS server to host my Knot, but since I didn't use a subdomain for my PDS I had some issues with Caddy redirecting properly.

A quick summary of that is that the Caddyfile for the PDS contains the "routes" *.mydomain.com and mydomain.com and redirects them to the PDS Docker container. I had added knot.mydomain.com to the Caddyfile to redirect to the Knot Docker container, but no matter what I tried, when ever knot.mydomain.com was being hit it was being caught by the wildcard and redirecting to the PDS container.

This is probably why they recommend using a pds.mydomain.com subdomain when setting up a PDS, but I didn't so well done to me 😒

The fix for this temporarily was to remove the wildcard which fixed the Knot redirect, but stops me from having any other account on my PDS, which isn't ideal as I want to set up a few accounts for some bots (or tasks) in the future.

So to me it seemed like playing around on my PDS server to fix this was going to end up with me breaking my PDS server and I didn't like the sound of that. I also had a feed that I've been hosting on a Raspberry Pi that I wanted to move off because I want to use the Pi for something else for a while. So I decided to grab another cheap server from upcloud.com to host all of my ATProto projects, and then keep my PDS as just a PDS.

I also thought this would be a nice test to see how well the Tangled Knot hosting holds up to a server failure and having to rebuild from a backup etc.

Spoiler: The fact that I'm writing this post meant it didn't go as smoothly as I wanted and just like my previous post, it was because of a mistake I made and not due to how Knots work.

I had a nice new server running and I set about setting up my Knot. I learnt from my mistakes last time and quickly had a fresh Knot running and I used a different domain that I had lying around (because who doesn't have a bunch of unused domains) to test connectivity before I used the real domain I wanted that was already used for the Knot on my PDS server.

All that was left to do was copy over the repositories directory and the database files from the old server to the new server. Since I only had 2 repositories and one was a test one and the other was a small Go bot I had been working on, I thought I could just scp the repositories directory and the database files from the old server to my laptop and then scp from my laptop to the new. I then switched over the domain to the new server, turned the old Knot container off and removed the Caddy config for it just in case and hey presto, Tangled was still able to see my Knot (but now on a new server) and it could still see the repositories, perfect. It worked!!!

Except it didn't.

When looking at the repositories on Tangled, there were no files. it was almost like it was a new repository and it gave me instructions on how to push to it. Seemed a bit odd. So I checked that I had copied the files over and it looked like everything was there. Next I tried cloning the repository but it kept telling me that it wasn't a git repository and I couldn't clone it. I even tried pushing a file to the test repository and I got the same message.

I then created a new repository through the UI, hosted on my Knot, created a file and pushed it up and it worked perfectly. I could see the file in the UI and I could also see a directory and some git files on my server. So why couldn't I see the repositories I had migrated?

I asked the kind chaps on the Tangled Discord and they were super useful asking me to check some database things and finally asked about file permissions. I'm not a strong Linux user but I know enough to have got me this far in my career so I had a quick look comparing the file permissions of the directories on the new server and those of the old server. The folders themselves had the same permissions, and I quickly tested a but of the sub directories and files and they looked ok as well. But if you've ever looked inside the directory of a git repo, you will know that there are tons of directories and files and I didn't want to check them all.

The problem, and I didn't know this but it makes sense thinking about it now, was that when I ran scp to copy them to my local laptop, some of the specific file/directory permissions on something must have been changed or removed. The answer was to Tar the directories up, run SCP to my laptop and over to the new and then UnTar them. Once I did that, all of the files appeared in the UI and I could push and pull to my hearts content!

So when I originally copied the directories across and thought "it's only a small directory, I can't be arsed to look up how to compress things again", I should have not been so lazy. If I had a ton of repositories and they were quite big, I wouldn't have dreamt of doing that and I would have looked it up and realised that I should Tar the files, then compress and move them.

Another user error, another lesson learnt but most importantly a proven test of how easy it can be to migrate or even restore a Tangled Knot from one server to another.