Featured image of post Safe Update of Manjaro

Safe Update of Manjaro

Making a backup BTRFS partition and updating Manjaro

History

It somehow happened that I updated my system fully, and both of my machines - the work machine and the personal server - broke. The Python 3.10 library crashed with a segfault, which caused the Kodi media server to malfunction. The Python Pip package also failed. It was quite frustrating in general. Fortunately, I had a backup. I really love Manjaro - it’s the best operating system for professional use, and I never had any problems with updating except maybe New Year’s Eve 😄 This is my second time, and both times were on New Year’s Eve. December 31, 2020, I made a full update of the system, but when I woke up to the new year, I found that X11 would not start because the drivers for Nvidia had expired. And then I thought: “Well, I fixed it in 5 minutes, how about others? Are they DevOps or ordinary users?” It seems like there was a transfer of drivers to the distribution’s repository, a simple renaming, but that was enough. And again New Year’s Eve! I install an update and Python3 crashes at the level of .so libraries 😄 The system works overall, but it needs something in many places and some software can fail. Right away the ranger stopped working, so I had to reinstall it again. This is what happened, and here’s the script below.

Script

 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
#!/usr/bin/env sh
## Making root BTRFS subvolume snapshot before making full Manjaro update

set -e

PARTITION="$(mount | awk '$3~/^\/$/{print $1}')"
SUBVOL="$(mount | awk '$3~/^\/$/{print $6}' | grep -oE 'subvol=[^,)]+' | cut -d= -f2- | sed -r 's/^\///g')"
MOUNTPOINT="/mnt"
BACKUP="$(date +%Y-%m-%d | xargs printf "backup/%s-%s" "$SUBVOL")"

main() {
  backup
  update
}

backup() {
  echo "Mounting $PARTITION to $MOUNTPOINT"
  mount "$PARTITION" "$MOUNTPOINT" -o subvol=/
  cd "$MOUNTPOINT"
  dirname "$BACKUP" | xargs mkdir -p
  if [ ! -d "$BACKUP" ]; then
    echo "Backing up $SUBVOL to $BACKUP"
    btrfs sub snap -r "$SUBVOL" "$BACKUP"
  else
    echo "$BACKUP exists already"
  fi
  cd /
  echo "Unmounting $MOUNTPOINT"
  umount "$MOUNTPOINT"
}

update() {
  echo "Running update"
  yay -Syu
}

main "$@"

Example Usage

And here’s what happens if the backup is made today already.

Licensed under Apache License, Version 2.0
Last updated on Nov 19, 2024 10:58 +0200
All rights reserved
Built with Hugo
Theme Stack designed by Jimmy