dot
vizie's NixOS desktop: Hyprland, CachyOS kernel and gaming tweaks
| 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 |
| 8 | set -euo pipefail |
| 9 | |
| 10 | disk=/dev/disk/by-id/ata-KINGSTON_SA400S37120G_50026B76820FD3CE |
| 11 | mnt=/mnt/backup |
| 12 | user=vizie |
| 13 | home=/home/$user |
| 14 | repo=$home/git/dot |
| 15 | wow="$home/Games/battlenet/drive_c/Program Files (x86)/World of Warcraft/_retail_" |
| 16 | |
| 17 | if [ "$EUID" -ne 0 ]; then |
| 18 | echo "Run it with sudo: sudo $0" >&2 |
| 19 | exit 1 |
| 20 | fi |
| 21 | if [ ! -e "$disk" ]; then |
| 22 | echo "The Kingston drive ($disk) isn't there." >&2 |
| 23 | exit 1 |
| 24 | fi |
| 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. |
| 28 | label=$(blkid -o value -s LABEL "$disk" || true) |
| 29 | fstype=$(blkid -o value -s TYPE "$disk" || true) |
| 30 | parts=$(lsblk -n -o NAME "$disk" | wc -l) |
| 31 | if [ "$fstype" = btrfs ] && [ "$label" = backup ]; then |
| 32 | echo "== Backup drive already formatted, updating it" |
| 33 | elif [ -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 |
| 37 | else |
| 38 | echo "The Kingston drive has something on it ($fstype${label:+, label $label}); not touching it." >&2 |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | mkdir -p "$mnt" |
| 43 | if ! mountpoint -q "$mnt"; then |
| 44 | mount -o compress=zstd /dev/disk/by-label/backup "$mnt" |
| 45 | fi |
| 46 | install -d -o "$user" "$mnt/nix-cache" "$mnt/wow" |
| 47 | |
| 48 | echo "== Saving the built system and the disko script" |
| 49 | sudo -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 | |
| 58 | echo "== WoW settings and addons" |
| 59 | rsync -a --delete "$wow/WTF" "$wow/Interface" "$mnt/wow/" |
| 60 | |
| 61 | echo "== Home folder (about 83 GB the first time)" |
| 62 | rsync -aHAXx --delete --info=progress2 --filter="merge $repo/backup-filter" "$home/" "$mnt/$user/" |
| 63 | |
| 64 | sync |
| 65 | echo "== Done" |
| 66 | du -sh "$mnt"/* |
| 67 | df -h "$mnt" |
| 68 | umount "$mnt" |