Try   HackMD

BTRFS auto snapshots on ubuntu

one of the cool features of BTRFS is filesystem-level snapshots. unfortunately, none of the ubuntu flavors uses them by default.

this guide serves for convenient utilizing of BTRFS snapshot and their automation.

Prerequisities

Root partition filesystem

in order to use BTRFS features, you must use BTRFS for your root partition, obviously.

during installation, your root partition entry must look like this:

/ btrfs

Software

Core

  • snapper - a basic 'engine' for snapshots management. it is an CLI utility
  • snapper-gui - a clear GUI on top of snapper
  • apt-btrfs-snapper - a daemon/hook, which automatically creates snapshots on any changing apt action (install,update,remove)

Dependencies

  • git
  • python3
  • libgtksourceview-3.0-1
  • gir1.2-gtksource-3.0
  • python3-dbus
  • python3-setuptools
  • python3-distutils-extra

Installation

Note: the sharp # sign means that the command needs root privileges. you have to run that command either in elevated terminal or using sudo, eg.:

$ sudo apt install git

dependencies

# apt update
# apt install git python3 libgtksourceview-3.0-1 gir1.2-gtksource-3.0 python3-dbus python3-setuptools python3-distutils-extra

snapper

# apt install snapper

after installation, you need to create initial configuration for root partition

# snapper create-config /

snapper-gui

install from git repository:

$ git clone https://github.com/ricardo-vieira/snapper-gui/
$ cd snapper-gui/
# python3 setup.py install

apt-btrfs-snapper

install from git repository:

$ git clone https://github.com/agronick/apt-btrfs-snapper/
$ cd apt-btrfs-snapper/
# python3 setup.py install

Usage

snapper

a CLI utility for snapshots management. it can list, create, restore, delete snapshots as well as show diff between them.

it is encouraged to read this tutorial.

config

you need to create a subvolume configuration for your BTRFS partition(s). there must be at least one - root subvolume:

# snapper create-config /

create snapshot

# snapper create --description "before changes"

list snapshots

# snapper list

diff snapshots

# snapper diff 2..3

2 and 3 are snapshot numbers as shown in the list command

restore snapshot

# snapper undochange 2..3

2 and 3 are snapshot numbers as shown in the list command

snapper-gui

a GUI utility in which you can conveniently list snapshots, diffs and configs as well as create them.

apt-btrfs-snapper

a CLI utility and a daemon, which hooks into apt actions. it automatically creates two snapshots before and after every apt install, update and remove action.

it also has convenient 'shortcut' commmands for creating and restoring snapshots as well as deleting snapshots older than X days.

# apt-btrfs-snapper

shows more info