Skip to content

Instantly share code, notes, and snippets.

@shello
Created June 13, 2021 10:30
Show Gist options
  • Save shello/64c5e35d83b99f67833404d8496d5050 to your computer and use it in GitHub Desktop.
Save shello/64c5e35d83b99f67833404d8496d5050 to your computer and use it in GitHub Desktop.
Pacman hook: Take a snapshot of the root dataset before any operation
# ZFS Root Snapshot Pacman Hook
# 2021 Filipe Rodrigues<shello@shello.org>
#
# Take a snapshot of the root dataset before any pacman operation.
# See: https://man.archlinux.org/man/alpm-hooks.5
# Depends on: pacman, zfs, coreutils
# Location: /etc/pacman.d/hooks/zfs_snapshot.hook
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Description = Taking a snapshot of root dataset
When = PreTransaction
Exec = /bin/sh -c '/usr/bin/zfs snapshot "$(/usr/bin/zfs list -Ho name /)"@"auto-pacman-$(/usr/bin/date +%F_%T_%Z)"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment