55 lines
1.8 KiB
Bash
55 lines
1.8 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Purpose : Configure Snapper so update can snapshot / before each upgrade
|
|
# (updates.d/09-snapshot.sh). Only applies when / is btrfs, which is
|
|
# archinstall's default. /home is a separate subvolume and is not
|
|
# included in the snapshots.
|
|
|
|
if [ "$(findmnt -no FSTYPE /)" != "btrfs" ]; then
|
|
echo "/ is not btrfs; skipping Snapper setup."
|
|
exit 0
|
|
fi
|
|
|
|
set -e
|
|
|
|
source "$HOME/.local/share/coredesktop/utils.sh"
|
|
|
|
install_packages snapper
|
|
|
|
if [ ! -f /etc/snapper/configs/root ]; then
|
|
echo "Creating Snapper config for /..."
|
|
|
|
# create-config makes its own /.snapshots subvolume and fails if the path
|
|
# already exists. archinstall mounts a separate @.snapshots subvolume there,
|
|
# so follow the Arch wiki: unmount it, let snapper create its config, then
|
|
# swap snapper's nested subvolume back out for the @.snapshots mount.
|
|
if mountpoint -q /.snapshots; then
|
|
sudo umount /.snapshots
|
|
sudo rmdir /.snapshots
|
|
sudo snapper -c root create-config /
|
|
sudo btrfs subvolume delete /.snapshots
|
|
sudo mkdir /.snapshots
|
|
sudo mount /.snapshots
|
|
else
|
|
if [ -e /.snapshots ] && ! sudo rmdir /.snapshots 2>/dev/null; then
|
|
echo "/.snapshots exists and isn't an empty directory. Move it aside and run this again."
|
|
exit 1
|
|
fi
|
|
sudo snapper -c root create-config /
|
|
fi
|
|
|
|
# Keep only the last 5 pre-update snapshots, and no hourly timeline. Only set
|
|
# on a config we created, so a config you made yourself keeps its settings.
|
|
sudo snapper -c root set-config \
|
|
TIMELINE_CREATE=no \
|
|
NUMBER_CLEANUP=yes \
|
|
NUMBER_MIN_AGE=0 \
|
|
NUMBER_LIMIT=5 \
|
|
NUMBER_LIMIT_IMPORTANT=5
|
|
sudo systemctl disable --now snapper-timeline.timer 2> /dev/null || true
|
|
else
|
|
echo "Snapper config for / already exists."
|
|
fi
|
|
|
|
sudo systemctl enable --now snapper-cleanup.timer
|