dot

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

58 lines1906 bytesexecutable
1#!/usr/bin/env bash
2# Backs up the home folder and WoW's settings and addons to the Kingston SATA
3# SSD (sda), before the install wipes the NVMe drive (MIGRATION.md). Safe to
4# run again: the first run formats the drive (only if it is empty), later runs
5# 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=$(dirname "$(dirname "$(readlink -f "$0")")")
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/wow"
47
48echo "== WoW settings and addons"
49rsync -a --delete "$wow/WTF" "$wow/Interface" "$mnt/wow/"
50
51echo "== Home folder (about 83 GB the first time)"
52rsync -aHAXx --delete --info=progress2 --filter="merge $repo/backup-filter" "$home/" "$mnt/$user/"
53
54sync
55echo "== Done"
56du -sh "$mnt"/*
57df -h "$mnt"
58umount "$mnt"