SNAP-PAC(8)

NAME
snap-pac - Pacman hooks that use snapper to create pre/post btrfs snapshots like openSUSE's YaST

DESCRIPTION
This is a set of pacman hooks and script that causes snapper to automatically take a pre and post snapshot before and after pacman transactions, similar to how YaST does with OpenSuse. This provides a simple way to undo changes to a system after a pacman transaction. Because these are pacman hooks, it doesn't matter how you call pacman—whether directly, through an AUR helper, or using an alias—snapper will create the snapshots when pacman installs, upgrades, or removes a package. The pacman command used is logged in the snapper description for the snapshots. Additionally the snapshot numbers are output to the screen and to the pacman log for each snapper configuration during the pacman transaction. To undo changes from a pacman transaction, use snapper undochange. See snapper(8) and the following example. If you have severe breakage—like snapper is gone for some reason and you can't get it back—you'll have to resort to more extreme methods, such as taking a snapshot of the pre snapshot and making it the default subvolume or mounting it as /. Most likely you'll need to use a live USB to get into a chroot environment to do any of these things. Snapper has a snapper rollback feature, but your setup has to be properly configured to use it. The exact procedure depends on your specific setup. Be careful.

CONFIGURATION
Configuration is done via configuration files. The defaults of the following should be suitable for most users, so you may not need to do any configuration at all. Follow the pattern of bash shell variables (VAR=setting) in each configuration file below. Comments can be added by adding # before the comment. Example configuration files are located at /etc/snap-pac.conf.example and /etc/snap-pac/root.conf.example. The following settings can be changed in the main snap-pac configuration file /etc/snap-pac.conf: ABORT_ON_FAIL=yes or no
    When set to "yes" this causes pacman to abort a transaction if the snap-pac pre hook fails. This prevents an upgrade/installation/removal from occurring if a pre snapshot cannot be performed. Default is "no".
DESC_LIMIT=integer
    Number of characters to limit length of descriptions used for snapper. Default is "72".
The following are possible settings used on each specific snapper configuration you have. To use them, first create the folder /etc/snap-pac if it does not already exist. Then create a file for the snapper configuration file you want these settings to apply to. For example, for the snapper configuration named root, create the file /etc/snap-pac/root.conf. snap-pac requires and expects configuration files to end in .conf. SNAPSHOT=yes or no
    Perform pacman pre/post snapshots for this configuration. In other words, if you want snapper to run before and after a pacman transaction, set this to "yes". Default is "no", except for the root configuration which is "yes".
CLEANUP_ALGORITHM
    snapper algorithm used in cleaning up the pacman pre/post snapshots. See snapper(8) for list of valid options. Default is "number".
PRE_DESCRIPTION=string
    snapper description used for the pacman pre snapshot. Default is the parent program (usually pacman) that called the snapshot script.
POST_DESCRIPTION=string
    snapper description used for the pacman post snapshot. Default is the list of packages that were installed/upgraded/removed during the transaction.

ENVIRONMENT VARIABLES
To temporarily prevent snapshots from being performed for a single pacman command, set the environment variable SNAP_PAC_SKIP. For example:
        $ sudo SNAP_PAC_SKIP=y pacman -Syu

EXAMPLE
Installing the nano package as normal:
        # pacman -S nano
        resolving dependencies...
        looking for conflicting packages...
        Packages (1) nano-2.5.3-1
        Total Installed Size:  2.14 MiB
        :: Proceed with installation? [Y/n] Y
        (1/1) checking keys in keyring                               [######################################] 100%
        (1/1) checking package integrity                             [######################################] 100%
        (1/1) loading package files                                  [######################################] 100%
        (1/1) checking for file conflicts                            [######################################] 100%
        (1/1) checking available disk space                          [######################################] 100%
        :: Running pre-transaction hooks...
        (1/1) Performing snapper pre snapshots for the following configurations...
        => root: 1033
        :: Processing package changes...
        (1/1) installing nano                                        [######################################] 100%
        :: Running post-transaction hooks...
        (1/1) Performing snapper post snapshots for the following configurations...
        => root: 1034
The snapper snapshot number is given for each snapper configuration that is used. Tip: this is also logged in pacman's log). And here are the snapshots:
        # snapper -c root list -t pre-post | tail -n 1
        1033  | 1034   | Fri 22 Apr 2016 01:54:13 PM CDT | Fri 22 Apr 2016 01:54:14 PM CDT | pacman -S nano      |
What changed?
        # snapper -c root status 1033..1034
        +..... /etc/nanorc
        c..... /etc/snapper/.snap-pac-pre
        +..... /usr/bin/nano
        +..... /usr/bin/rnano
        +..... /usr/share/doc/nano
        +..... /usr/share/doc/nano/faq.html
        +..... /usr/share/doc/nano/fr
        +..... /usr/share/doc/nano/fr/nano.1.html
        +..... /usr/share/doc/nano/fr/nanorc.5.html
        +..... /usr/share/doc/nano/fr/rnano.1.html
I truncated the above output, but it continues. See the manpage for snapper to see what each symbol means. You can also do snapper diff in the same way—I'll spare you that one. To undo the upgrade:
        # snapper -c root undochange 1033..1034
        create:0 modify:3 delete:100
And nano is now gone, along with all the files it changed:
        $ pacman -Qi nano
        error: package 'nano' was not found

TROUBLESHOOTING

  snap-pac is only taking snapshots of the root configuration
That's the default behavior. See CONFIGURATION.

  No snapshots are being taken when I run pacman
No snapper configurations are set up for snap-pac's pacman hooks. By default snap-pac will take snapshots for the root configuration and any other configuration which has SNAPSHOT set to yes in its configuration file. See CONFIGURATION.

  After restoring snapshot from snap-pac, pacman database is locked
The pre/post snaphots are taken while pacman is running, so this is expected. Follow the instructions pacman gives you (e.g., removing the lock file).

FAQ

  Does snap-pac backup non-btrfs /boot partitions?
Nope. But you can add a hook that does it for you. It would be something like the following:
        [Trigger]
        Operation = Upgrade
        Operation = Install
        Operation = Remove
        Type = Package
        Target = linux
        [Action]
        Description = Backing up /boot...
        When = PreTransaction
        Exec = /usr/bin/rsync -avzq --delete /boot /.bootbackup

  How do I link old kernel modules?
This behavior is no longer a part of this package. Use a pacman hook like the following:
    [Trigger]
    Operation = Upgrade
    Operation = Install
    Operation = Remove
    Type = Package
    Target = linux
    [Action]
    Description = Symlinking old kernel modules...
    When = PostTransaction
    Exec = /usr/bin/bash -c "find /usr/lib/modules -xtype l -delete; ln -sv /.snapshots/$(snapper -c root list | awk 'END{print $1}')/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/"

HOMEPAGE
https://github.com/wesbarnett/snap-pac

AUTHORS
Wes Barnett <wes@wbarnett.us>

SEE ALSO
alpm-hooks(5), snapper(8), snapper-configs(5), pacman(8)