Home Wiki > openSUSE:Snapper Tutorial
Sign up | Login

openSUSE:Snapper Tutorial

tagline: From openSUSE

Snapper Tutorial

We assume you have installed openSUSE 12.1 using YaST and selected btrfs for your root and home file system.

First let us check how YaST has configured snapper:

# snapper list-configs
Config | Subvolume
-------+----------
root   | /  

As you can see YaST has created a snapper config called "root" for your root file system. You can see what snapshots exist:

# snapper list
Type   | # | Pre # | Date                         | Cleanup  | Description |  Userdata
-------+---+-------+------------------------------+----------+-------------+---------
single | 0 |       |                              |          | current     |         
single | 1 |       | Tue 22 Nov 2011 10:30:02 CET | timeline | timeline    |

Snapshot #0 always refers to the current system. There might already be several other snapshots depending on the uptime of your system and on whether you already used YaST or zypper.

Now we want to try snapper as a undo tool for YaST. First we run YaST:

# yast2 system_settings

Within YaST enable the SysReq. After you have finished YaST you see two new snapshots:

# snapper list
Type   | # | Pre # | Date                         | Cleanup  | Description          | Userdata
-------+---+-------+------------------------------+----------+----------------------+---------
single | 0 |       |                              |          | current              |         
single | 1 |       | Tue 22 Nov 2011 10:30:02 CET | timeline | timeline             |         
pre    | 2 |       | Tue 22 Nov 2011 10:41:28 CET | number   | yast system_settings |         
post   | 3 | 2     | Tue 22 Nov 2011 10:41:49 CET | number   |                      |         

It's time to explain the type of snapshots. Snapper creates a snapshot before and after YaST runs, these snapshots are called pre and post respectively. The post snapshots knows which pre snapshots belongs to it. By having a pre and post snapshot we can see what changes happened to the file system while YaST was running. Single snapshots have no special relationship to other snapshots.

Using snapper it is easy to see what has changed while YaST was running. To do so you have to pass the number of the pre and post snapshot:

# snapper status 2..3
c... /etc/sysctl.conf

The 'c' means that the content of the file has changed.

We can also see the diff of the file:

# snapper diff 2..3
--- /.snapshots/2/snapshot/etc/sysctl.conf      2011-11-22 10:35:43.355493753 +0100
+++ /.snapshots/3/snapshot/etc/sysctl.conf      2011-11-22 10:41:47.019512185 +0100
@@ -17,7 +17,7 @@
 # See sysctl.conf(5) and sysctl(8) for more information
 #
 ####
-kernel.sysrq = 0
+kernel.sysrq = 1
 net.ipv4.ip_forward = 0
 net.ipv4.tcp_syncookies = 1
 net.ipv6.conf.all.forwarding = 0

So, if you don't like the change done by YaST and want to revert it call:

# snapper undochange 2..3
create:0 modify:1 delete:0
undoing change...
undoing change done

But note that snapper does not tell the kernel about the change like YaST did so you must either do so yourself or reboot.

During installation YaST does not setup a snapper config for /home. We can do so manually:

# snapper -c home create-config /home

Whenever you want to use snapper for /home you must provide the option -c home.

Now you can see what files have changed since the last hourly snapshot:

# snapper -c home list
Type   | # | Pre # | Date                         | Cleanup  | Description | Userdata
-------+---+-------+------------------------------+----------+-------------+---------
single | 0 |       |                              |          | current     |         
single | 1 |       | Tue 22 Nov 2011 11:30:01 CET | timeline | timeline    |         
# snapper -c home status 1..0
comparing snapshots... done
+... /home/tux/just-married.jpg

The '+' sign means that the file is new.

If you manually want to create a snapshot use:

# snapper -c home create --description "before the big cleanup"

Finally yast2-snapper provides a YaST UI for snapper.

Snapper.png

Snapper demo