Subversion Repositories sysadmin_scripts

Rev

Rev 96 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
96 rodolico 1
snapshot is a simple Perl script used to manage ZFS snapshots. It is designed to be run from a cron job.
2
 
3
It's configuration file is assumed to be snapShot.yaml in the same directory as the script. For those of us who prefer perl data
4
structures, there is a script, confToYAML.pl which will take a perl definition of the configuration file and convert to yaml. Call 
5
it with
6
confToYAML.pl < snapShot.cfg > snapShot.YAML
7
A sample of snapShot.cfg is included.
8
 
9
NOTICE: this uses the perl module yaml-tiny to read the configuration file
10
   Debian Based Systems: apt install libyaml-tiny-perl
11
   BSD Systems: cpan -i YAML::Tiny
12
 
13
Every place that uses a frequency (ie, retention, frequency, slop) is expressed as a number of seconds. This should be an integer,
14
optionally followed by a space and a unit. hour, day, week, month and year are acceptable units.
15
 
16
== globals
17
 
18
TESTING - if non-zero (true), will print the commands that would be executed to /tmp/snapshot
19
slop - Number of seconds of slop allowed a cron job to determine if a new snapshot should be taken.
20
listingkeys - Headers from the output of zfs list and zfs list -t snapshot, so we know which column is which
21
 
22
There is no guarantee that cron and the timestamp embedded in the snapshot name will be exactly right. For example, if you were to
23
run the cron job every hour, you may be off by a minute or two when deciding to create a new snapshot. 'slop' allows for this by
24
saying "if we are slop seconds from needing a new snapshot, pretend we need it now". For a hourly cron job checking for daily 
25
snapshots, slop could be something like '1 hour'
26
 
27
== datasets
28
 
29
Basically, you choose one or more datasets to be managed. Each dataset can have three flags:
30
 
31
retention: How long a to keep a snapshot after it was created
32
frequency: How often to create a new snapshot
33
recursive: Adds the -r command to both zfs snapshot and zfs destroy commands if set to non-zero
34
 
35
The dataset key should be a regex, so escape all forward slashes and periods, ie for 
36
storage/iscsi.shares
37
you would use
38
storage\/iscsi\.shares
39
The regex must match the entire string to keep from matching storage/iscsi.shares/local_stuff, etc... If you want to match
40
child datasets, end the regex with '.*', ie
41
storage\/iscsi\.shares.*
42
 
43
See $config->{'datasets'}
44
 
45
== snapshots
46
 
47
Snapshots will be managed only if they match the parse regex, and will be created using the template string, which must be parsable 
48
by strftime. Care must be taken by the user to ensure parse and template match, and are correctly identified by parseFields.
49
 
50
See $config{'snapshot'}.