dot

vizie's NixOS desktop: Hyprland, CachyOS kernel and gaming tweaks

68 lines2396 bytesexecutable
1#!/usr/bin/env bash
2# Backs up what MIGRATION.md section 1 lists to the Kingston SATA SSD (sda):
3# the built system and disko script, WoW's settings and addons, and the home
4# folder. Safe to run again: the first run formats the drive (only if it is
5# empty), later runs only copy what changed.
6#
7# sudo ~/git/dot/tools/backup-to-sata
8set -euo pipefail
9
10disk=/dev/disk/by-id/ata-KINGSTON_SA400S37120G_50026B76820FD3CE
11mnt=/mnt/backup
12user=vizie
13home=/home/$user
14repo=$home/git/dot
15wow="$home/Games/battlenet/drive_c/Program Files (x86)/World of Warcraft/_retail_"
16
17if [ "$EUID" -ne 0 ]; then
18 echo "Run it with sudo: sudo $0" >&2
19 exit 1
20fi
21if [ ! -e "$disk" ]; then
22 echo "The Kingston drive ($disk) isn't there." >&2
23 exit 1
24fi
25
26# Format only a drive with nothing on it, or reuse the backup drive from an
27# earlier run. Anything else (partitions, another file system) stops here.
28label=$(blkid -o value -s LABEL "$disk" || true)
29fstype=$(blkid -o value -s TYPE "$disk" || true)
30parts=$(lsblk -n -o NAME "$disk" | wc -l)
31if [ "$fstype" = btrfs ] && [ "$label" = backup ]; then
32 echo "== Backup drive already formatted, updating it"
33elif [ -z "$fstype" ] && [ "$parts" -eq 1 ]; then
34 echo "== Formatting $(readlink -f "$disk") (empty Kingston SSD) as 'backup'"
35 mkfs.btrfs -L backup "$disk"
36 udevadm settle
37else
38 echo "The Kingston drive has something on it ($fstype${label:+, label $label}); not touching it." >&2
39 exit 1
40fi
41
42mkdir -p "$mnt"
43if ! mountpoint -q "$mnt"; then
44 mount -o compress=zstd /dev/disk/by-label/backup "$mnt"
45fi
46install -d -o "$user" "$mnt/nix-cache" "$mnt/wow"
47
48echo "== Saving the built system and the disko script"
49sudo -u "$user" bash -euo pipefail -c '
50 cd "$1"
51 sys=$(nix build --no-link --print-out-paths .#nixosConfigurations.desktop.config.system.build.toplevel)
52 disko=$(nix build --no-link --print-out-paths .#nixosConfigurations.desktop.config.system.build.diskoScript)
53 nix copy --to "file://$2/nix-cache?compression=zstd" "$sys" "$disko"
54 echo "$sys" > "$2/nix-cache/system"
55 echo "$disko" > "$2/nix-cache/disko"
56' _ "$repo" "$mnt"
57
58echo "== WoW settings and addons"
59rsync -a --delete "$wow/WTF" "$wow/Interface" "$mnt/wow/"
60
61echo "== Home folder (about 83 GB the first time)"
62rsync -aHAXx --delete --info=progress2 --filter="merge $repo/backup-filter" "$home/" "$mnt/$user/"
63
64sync
65echo "== Done"
66du -sh "$mnt"/*
67df -h "$mnt"
68umount "$mnt"