My second day on linux, and... I broke my system again (sorta)... while trying to make a backup... - Sopuli
Spoiler: I fixed it again. So basically, when I woke up this morning my
intention was to harden my system’s security a bit. I was gonna spend some time
reading about a few different things until I felt like I could understand them
and the process of setting them up. After my experience yesterday
[https://sopuli.xyz/post/42253082], I thought it would be a good idea to create
a backup first before getting into any of that, so I spent the first part of my
day reading about that. I read around on some forums and determined I needed to
do three things: use rsync to create a system snapshot of everything but /home/,
use borg to backup everything in /home/, and do something involving “pacman -Q”
to backup all the packages I have installed. Sounds simple, right? Well… I spent
some more time reading about how to do each of these things, until I finally
felt ready to give it a go. The first thing I did was create the pacman lists of
all my installed packages (one list for explicit installs, and one that includes
all dependencies). Easy enough. The reason I did this first was so it would be
included in my rsync backup, which is what I decided to do next. Before even
worrying about backing up to my external drive, I wanted to test it out first
locally, so I made a “backups” folder in /home/, and used that as the
destination for rsync. Since I didn’t have Borg set up yet, and I wanted to
harden my system’s security before connecting to the internet to download
outside packages, I decided not to exclude /home/ from this first rsync backup.
Are you starting to see where this is going? When I ran the command in Bash, of
course I didn’t know what to expect. At first I was a bit startled at all the
outputs zooming by, but I decided this was probably normal, so I pulled up
System Monitor and just watched for a while. I was somewhat surprised to see so
many flatpaks, since I’m on Endeavour, but I guess that’s normal too. I didn’t
realize something was wrong until I noticed the pathways in the outputs kept
cycling through the folder under “backups” that I titled specifically for the
rsync. And every couple of minutes, the pathways got slightly longer, as if they
expanded an extra layer. It dawned on me that I had created an endless loop when
I put my destination folder in /home/, though I didn’t make an exclusion for it.
So I panicked a bit, as one does, and since I didn’t know that I could simply
abort the process with ctl+c, I closed Bash. Not a great idea, but I didn’t know
what else to do. Anyway, so I checked the backup that I had created and it was
quite large. About 27 GiB. Not enormous, but definitely larger than it had to
be. I tried deleting it but it wouldn’t let me. So I sought a solution and tried
a fuser command, and got a big long list of leftover PIDs that I was apparently
supposed to kill to conclude the processes that got cut off when I closed Bash
in the middle of a script. That seemed a little overwhelming though and I didn’t
feel quite comfortable with it, so I decided to try rebooting instead… …and the
result was that it got stuck on some sort of dracut initqueue hook with no time
limit while attempting to boot. So, once again despairing, I walked away for a
while and tried searching for a fix on my phone. Fortunately by the time I came
back it had miraculously booted up. Assuming this had cleared the stuck
processes preventing me from deleting the rogue backup file, I tried deleting it
again and it still wouldn’t let me. So I reran the fuser command and killed all
the leftover PIDs and my screen immediately went black. I shut it down from the
power button, and turned it back on, and thankfully it booted up fine (better
than the previous time, at least). So long story short, I ended up doing a sudo
-rm -rf on the rogue backup and that worked like a charm. Then I reran rsync
with an exclusion for the folder the destination was in, and it went much
better. Still a big rush of outputs, which makes total sense, but it concluded
on its own after a couple minutes and the total size was only about 18GiB (talk
about bloat on a fresh install!!!). Not bad, though. I poked around a little
trying to optimize it with more exclusions, or alternatively with a white list
inclusion command, but I used a du command to see what folders were taking up
the most space and ultimately I really could’ve only saved a few GiB by
excluding some var/cache/ folders, but it wouldn’t really have been worth the
added inconvenience if I ever have to do a complete system restore. A big chunk
of it was the /home/ folder anyway, and that won’t be included in future backups
once I get borg set up. So that’s mostly it. It was already evening at this
point, and I had mostly forgotten to eat during the thick of it, so I ate some
dinner and then got out my external hard drive to try to make a real backup. My
first attempt failed, of course, because it wasn’t formatted (as I soon
learned). I noticed a lot of errors in the outputs so I did a ctl+c this time,
which ended the process much more neatly than before. So then I learned how to
format a hard drive as a btrfs, and then I decided while I was at it that I
might as well learn how to encrypt it, so I did that too. And then I had to
format it again, so I did. And then I reran the rsync and it worked perfectly!
Then I unmounted the drive and closed the encrypted container before unplugging
it, and that concludes my first real external backup on linux! I did not expect
it to take all day, but next time will be much smoother. Tomorrow I will finally
get to harden my system security, and if that doesn’t take all day then I’ll
install borg and back up my /home/ folder. After that, I’ll be ready to install
some more software and start playing around to see what my system can do!