about summary refs log tree commit diff
path: root/content/posts/2023-09-02-setup-external-backup.md
blob: 6a94158597da37ce9720d2803b7f4c210d507fa1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
title: "Setup backup on external disk"
date: 2023-09-02
draft: true
lang: en
categories: [ blog ]
tags: []
translationKey: "2023-09-02-setup-external-backup"
---

## Backstory

A few weeks ago (not today), I fucked up:
During irregular disk cleanup, I accidentally removed the config folder!

Fortunately, I "backed up" the config with git, didn't I? 😌

Well yes, but actually no! 🥲 I did commit, but I didn't push.
The latest pushed config had been 9 months before this incident.

On top of that, many programs generate unreadable configs, which I prefer not
to put into version control, or put sensitive information or large data into
`.config`, which shouldn't be pushed into a remote repository on a server I
don't own.  For example, nheko puts authentication info there, and after this
incident I lost the session with several messages---well, matrix's irregularly
regular decryption failure could be expanded into a post on its own, so let's
not digress.

And then there are more things to back up than just configs, say, my photos and
music.  I mirror them between my devices with [syncthing], providing
redundancy, but [syncthing is not backup][syncthing-failure],
and neither is [RAID][raid-not-backup]

[syncthing]: https://syncthing.net/
[syncthing-failure]: https://forum.syncthing.net/t/syncthing-deleted-all-files-on-every-device/20518
[raid-not-backup]: https://www.raidisnotabackup.com/

I should back them up, or I might one day be doomed to repeat the mistake.

## Preparation

Despite the bitterness from the partial data loss, I kinda didn't have the
spoon to do what I must, so I've been delaying it hitherto.

### Hardware

One of the reason I was cleaning up the disk in the first place was that it's
start to be filled up, so I bought a large hard drive to store more data and
backup.  Doesn't seem too safe, I know: if the hard drive gets lost or broken,
I'll lose both the main data and the backup, but with a limited budget and
space, that's good enough for now.

I got a Seagate One Touch 2 TB[^0] HDD.  It seems to come with builtin backup
software, which doesn't support Linux of course, and I likely wouldn't use it
even if it did.  A USB hub is also needed, as my laptop has a limited number of
USB ports.

### Formatting

Coming with the hard drive are several files, such as an `.exe` program to
initialize the backup, I suppose.  I don't need these, and the disk can be
formatted ~~right away~~ after I do full-disk encryption on that.

No partitioning is needed: while I do seek [vegan alternative][margarine], I
intended to use [btrfs][btrfs-kernel] as the file system, which can create
subvolumes, which can act as separate mounted partitions.  I will just reformat
the existing partition to btrfs.

```sh
mkfs.btrfs -L margarine /dev/sdb1
```

[margarine]: https://outerheaven.club/notice/AZ8wYpKOyp2p329V5M
[btrfs-kernel]: https://www.kernel.org/doc/html/latest/filesystems/btrfs.html

I intend to have three subvolumes, one for big data (not Big Data™) such as
movies or music, one for more personal data and another for backup:

```sh
mount /dev/sdb1 /mnt
btrfs subvolume /mnt/data/hoard
btrfs subvolume /mnt/data/perso
btrfs subvolume /mnt/backup
```

Finally, I need to declare those in the nix hardware configuration file.


```nix
{
  (...)
  fileSystems = {
    "/" = {
      (...)
    };
    "/data/hoard" = {
      device = "/dev/disk/by-uuid/[subvolume uuid]";
      fsType = "btrfs";
      options = [ "subvol=data/hoard" "compress-force=zstd" "noatime" ];
    };
    "/data/perso" = {
      device = "/dev/disk/by-uuid/[subvolume uuid]";
      fsType = "btrfs";
      options = [ "subvol=data/perso" "compress-force=zstd" "noatime" ];
    };
    "/backup" = {
      device = "/dev/disk/by-uuid/[subvolume uuid]";
      fsType = "btrfs";
      options = [ "subvol=backup" "compress-force=zstd" ];
    };
  };
  (...)
}
```

## Setting up

[^0]: That means 1.81 [TiB] and I feel cheated sometimes.

[TiB]: https://en.wikipedia.org/wiki/Byte#Multiple-byte_units.