Skip to content

Instantly share code, notes, and snippets.

@gchamon
Last active March 31, 2024 02:54
Show Gist options
  • Save gchamon/a10a23e258477e8eca67c4aa84aaccb5 to your computer and use it in GitHub Desktop.
Save gchamon/a10a23e258477e8eca67c4aa84aaccb5 to your computer and use it in GitHub Desktop.
How to restore my borg backup

Installing the operating system

Use the anarchy install medium:

  • encrypted luks device
  • anarchy-advanced
  • lts kernel with base devel
  • clean desktop: kde
  • other configs as needed (Swap, UEFI, bluetooth, trackpad...) but mostly just install everything

Prerequisites to access the backup

  • bitwarden
  • borg
  • rsync
  • git
  • yay
sudo pacman -S bitwarden borg rsync git cifs-utils
mkdir ~/AUR
git clone https://aur.archlinux.org/yay.git ~/AUR/yay
cd ~/AUR/yay
makepkg -si
# after installing from aur, reinstall yay from yay to keep it updated
yay -S yay

Accessing the backup

  1. recorver the passwords from bitwarden:
  • samba server to mount the smb fs
  • [{namespace}] borg passphrase for the respective backup to restore
  1. mount the smb share:
sudo mkdir -p /mnt/storage
sudo mount -t cifs -o user=gchamon //192.168.0.5/storage /mnt/storage
  1. find the latest archive:
sudo borg list /mnt/storage/borg-backups/{device-name}/home
2023-01-30                           Mon, 2023-01-30 15:00:05 [HASH]
2023-01-31                           Tue, 2023-01-31 15:00:04 [HASH]
2023-02-01                           Wed, 2023-02-01 15:00:05 [HASH]
2023-02-02                           Thu, 2023-02-02 15:00:04 [HASH]
2023-02-03                           Fri, 2023-02-03 15:00:04 [HASH]
2023-02-06                           Mon, 2023-02-06 15:00:04 [HASH]
  1. either extract the borg backup to a separate folder or a separate drive:

If possible, it is better to extract the backup to a separate, larger drive, clean unwanted folders and then commit the files to the final folder.

mkdir ~/recover

# if using and external drive, change sdc1 to the appropriate device using lsblk
sudo mount /dev/sdc1 ~/recover

cd ~/recover

borg extract --list /mnt/storage/borg-backups/{device-name}/home::2023-02-06
borg extract --list /mnt/storage/borg-backups/{device-name}/etc::2023-02-06

NOTE: boot, srv and var are backed-up just in case, but are not necessary for a restoration

  1. install packages list first

Restore pacman configuration. When installing vanilla arch with archinstall databases like multilib are disabled. Restoring the pacman configuration will reenable them:

sudo rsync -va ~/recover/etc/pacman.d /etc
sudo cp ~/recover/etc/pacman.conf /etc
# update the system using the new databases
yay -Syu

It's also good to update the mirrors to those with less latency (change Brazil to current country):

yay -S reflector
sudo reflector -c Brazil -l 10 --sort rate --verbose -p http,https --save /etc/pacman.d/mirrorlist

Then we can install the packages in the backup.

yay -S --needed $(sudo cat ~/recover/home/gchamon/Documents/pkglist.txt)
  1. the camera shipped with Acer Nitro 5 isn't supported by the vanilla kernel and UVC must be patched. If restoring this device, go to https://github.com/gchamon/uvc and install the patch.

  2. restore etc and home

Important: if cloning a device into another, be careful to prevent modifying /etc/crypttab and /etc/fstab, otherwise it might need fixing.

sudo rm ~/recover/etc/{fstab,crypttab}
sudo rsync -va ~/recover/home/ /home/
sudo rsync -va ~/recover/etc/ /etc/

Since we restored packages using yay before restoring /etc, we should not have any issues with files existing in /etc when installing packages. However, this can occur later. In any case bash -c 'yay -S --overwrite \* {package-name} is enough to overwrite those files.

  1. reboot and finish installation

Things that might need attention after installing:

fonts and p10k

Using powerlevel10k requires meslo nerd fonts patched for p10k to be installed. Make sure they are installed and run p10k configure.

Autofs

Make sure autofs service is enabled and running:

sudo systemctl enable autofs
sudo systemctl start autofs

The backup from etc will have the correct configurations for it to access and mount the samba shared FS locally.

Reconfigure backups

Reinstall borg backups from https://github.com/gchamon/borg-automated-backups. Since cronio is reinstalled, make sure that the cronjob installed at /etc/cron.hourly/yay_pkglist is running correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment