Rockstable Wiki:

Snapper

About

Create config-template

/etc/snapper/config-templates/snapper.template

   1 ### SNAPPER-CONFIGS(5)# Filesystem Snapshot Management                
   2 ### Boolean values must be "yes" or "no".
   3 
   4 SUBVOLUME="/"
   5         # Path of the subvolume or mount point.
   6         # There is no default value. The value must always be specified.
   7 
   8 FSTYPE=btrfs
   9         # Filesystem type for the subvolume.
  10         # Default value is "btrfs" but it's recommended to always specify the 
  11         # filesystem type.
  12 
  13 ALLOW_USERS=""
  14         # List of users allowed to operate with the config. The user-names 
  15         # must be separated by spaces. Spaces in usernames can be escaped with 
  16         # a "\".
  17         # Also see the PERMISSONS section in snapper(8).
  18         # Default value is "" but "root" is always implicitly included.
  19 
  20 ALLOW_GROUPS="snapper"
  21         # List of groups allowed to operate with the config. The group-names 
  22         # must be separated by spaces. Spaces in group-names can be escaped 
  23         # with a "\".
  24         # Also see the PERMISSONS section in snapper(8).
  25         # Default value is "".
  26 
  27 SYNC_ACL=yes
  28         # Defines whether snapper will sync the users and groups from 
  29         # ALLOW_USERS and ALLOW_GROUPS to the ACL of the .snapshots directory.
  30         # Also see the PERMISSONS section in snapper(8).
  31         # Default value is "no".
  32         # New in version 0.2.0.
  33 
  34 BACKGROUND_COMPARISON=yes
  35         # Defines whether pre and post snapshots should be compared in the 
  36         # background after creation.
  37         # Default value is "yes".
  38 
  39 ### CLEANUP ALGORITHMS
  40 ######################
  41 
  42 ### NUMBER
  43 NUMBER_CLEANUP=no
  44         # Defines whether the number cleanup algorithm should be run for the 
  45         # config.
  46         # Default value is "no".
  47 
  48 NUMBER_MIN_AGE=1800
  49         # Minimal age for snapshots to be deleted by the number cleanup 
  50         # algorithm.
  51         # Default value is "1800".
  52 
  53 NUMBER_LIMIT=50
  54         # Defines how many snapshots the number cleanup algorithm should 
  55         # keep. The youngest snapshots will be kept.
  56         # Default value is "50".
  57 
  58 NUMBER_LIMIT_IMPORTANT=10
  59         # Defines how many important snapshots the number cleanup algorithm 
  60         # should keep. Important snapshots have important=yes in the userdata. 
  61         # The youngest important snapshots will be kept.
  62         # The number of normal and important snapshots are counted 
  63         # independently.
  64         # Default value is "10".
  65         # New in version 0.1.8.
  66 
  67 ### TIMELINE
  68 TIMELINE_CREATE=yes
  69         # Defines whether hourly snapshots should be created.
  70         # Together with the timeline cleanup algorithm this will create a 
  71         # collection of snapshots with more snapshots is the near past and less 
  72         # snapshots in the far past.
  73         # Default value is "no".
  74 
  75 TIMELINE_CLEANUP=yes
  76         # Defines whether the timeline cleanup algorithm should be run for 
  77         # the config.
  78         # Default value is "no".
  79 
  80 TIMELINE_MIN_AGE=14400
  81         # Minimal age for snapshots to be deleted by the timeline cleanup 
  82         # algorithm.
  83         # Default value is "1800".
  84 
  85 TIMELINE_LIMIT_HOURLY=23
  86         # Defines how many hourly snapshots the timeline cleanup algorithm 
  87         # should keep. An hourly snapshot is the first snapshot in an hour. The 
  88         # youngest hourly snapshots will be kept.
  89         # Default value is "10".
  90 
  91 TIMELINE_LIMIT_DAILY=14
  92         # Defines how many daily snapshots the timeline cleanup algorithm 
  93         # should keep. A daily snapshot is the first snapshot in a day. The 
  94         # youngest daily snapshots will be kept.
  95         # Default value is "10".
  96 
  97 TIMELINE_LIMIT_MONTHLY=6
  98         # Defines how many monthly snapshots the timeline cleanup algorithm 
  99         # should keep. A monthly snapshot is the first snapshot in a month. The 
 100         # youngest monthly snapshots will be kept.
 101         # Default value is "10".
 102 
 103 TIMELINE_LIMIT_YEARLY=1
 104         # Defines how many yearly snapshots the timeline cleanup algorithm 
 105         # should keep. A yearly snapshot is the first snapshot in a year. The 
 106         # youngest yearly snapshots will be kept.
 107         # Default value is "10".
 108 
 109 ### EMTPY PRE POST
 110 EMPTY_PRE_POST_CLEANUP=yes
 111         # Defines whether the empty-pre-post cleanup algorithm should be run 
 112         # for the config.
 113         # Default value is "no".
 114 
 115 EMPTY_PRE_POST_MIN_AGE=1800
 116         # Minimal age for snapshots to be deleted by the empty-pre-post 
 117         # cleanup algorithm.
 118         # Default value is "1800".
 119 

Create config

Create snapper config from a template

   1 # snapper -c testfs create-config -t snapper.template /testfs
   2 # snapper list-configs                                       
   3 Konfiguration | Subvolume       
   4 --------------+-----------------
   5 rootfs        | /               
   6 home          | /home           
   7 libvirt       | /var/lib/libvirt
   8 log           | /var/log        
   9 srv           | /srv            
  10 testfs        | /testfs         

Delete config

   1 # snapper -c testfs delete-config                        
   2 

List configs

   1 # snapper list-configs
   2 Konfiguration | Subvolume       
   3 --------------+-----------------
   4 rootfs        | /               
   5 home          | /home           
   6 libvirt       | /var/lib/libvirt
   7 log           | /var/log        
   8 srv           | /srv    

Query config information

   1 # snapper -c rootfs get-config
   2 Schl├╝ssel              | Wert   
   3 -----------------------+--------
   4 ALLOW_GROUPS           | snapper
   5 ALLOW_USERS            |        
   6 BACKGROUND_COMPARISON  | yes    
   7 EMPTY_PRE_POST_CLEANUP | yes    
   8 EMPTY_PRE_POST_MIN_AGE | 1800   
   9 FSTYPE                 | btrfs  
  10 NUMBER_CLEANUP         | no     
  11 NUMBER_LIMIT           | 50     
  12 NUMBER_LIMIT_IMPORTANT | 10     
  13 NUMBER_MIN_AGE         | 1800   
  14 SUBVOLUME              | /      
  15 SYNC_ACL               | yes    
  16 TIMELINE_CLEANUP       | yes    
  17 TIMELINE_CREATE        | yes    
  18 TIMELINE_LIMIT_DAILY   | 14     
  19 TIMELINE_LIMIT_HOURLY  | 23     
  20 TIMELINE_LIMIT_MONTHLY | 6      
  21 TIMELINE_LIMIT_YEARLY  | 1      
  22 TIMELINE_MIN_AGE       | 14400  

Cleanup timelines

This may be useful after changing the snapper config for a filesystem. The cleanup itself happens in the background (lazy space reclaim).

   1 # snapper -c rootfs cleanup timeline 
   2 

Cleanup timelines

   1 root@infinitas ~ # cd /etc/snapper/configs 
   2 root@infinitas /etc/snapper/configs # for FILESYSTEM in *; do snapper -c $FILESYSTEM cleanup timeline; done
   3 root@infinitas /etc/snapper/configs # watch -n1 'df -m'
   4 

A small script to rename/link snapshots
/usr/local/sbin/snapper_rename.sh

   1 #!/bin/bash
   2 TARGET_DIR=/var/www/debian/snapper
   3 find "$TARGET_DIR" -type l -exec unlink {} \;
   4 
   5 for SNAPSHOT in /var/spool/apt-mirror/.snapshots/*; do
   6         DATE=$(stat --printf=%y "$SNAPSHOT" | date -d - '+%F')
   7         ln -s "$SNAPSHOT/snapshot/" "$TARGET_DIR/$DATE"
   8 done

Rockstable Wiki: Snapper (last edited 2020-04-21 11:48:29 by RockStable)