From a1f5e4c0c006e16a5047a16fc65c9b3663adb81e Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Wed, 4 Dec 2019 22:19:29 -0500 Subject: [PATCH] Add cache-dir option. --- README.md | 4 ++++ sanoid | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bc8ed83..d5e143d 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ Which would be enough to tell sanoid to take and keep 36 hourly snapshots, 30 da Specify a location for the config file named sanoid.conf. Defaults to /etc/sanoid ++ --cache-dir + + Specify a directory to store the zfs snapshot cache. Defaults to /var/cache/sanoid + + --take-snapshots This will process your sanoid.conf file, create snapshots, but it will NOT purge expired ones. (Note that snapshots taken are atomic in an individual dataset context, not a global context - snapshots of pool/dataset1 and pool/dataset2 will each be internally consistent and atomic, but one may be a few filesystem transactions "newer" than the other.) diff --git a/sanoid b/sanoid index 2b566ef..fd39f3a 100755 --- a/sanoid +++ b/sanoid @@ -11,15 +11,19 @@ use strict; use warnings; use Config::IniFiles; # read samba-style conf file use Data::Dumper; # debugging - print contents of hash -use File::Path; # for rmtree command in use_prune +use File::Path 'make_path'; use Getopt::Long qw(:config auto_version auto_help); use Pod::Usage; # pod2usage use Time::Local; # to parse dates in reverse use Capture::Tiny ':all'; -my %args = ("configdir" => "/etc/sanoid"); +my %args = ( + "configdir" => "/etc/sanoid", + "cache-dir" => "/var/cache/sanoid" +); GetOptions(\%args, "verbose", "debug", "cron", "readonly", "quiet", - "monitor-health", "force-update", "configdir=s", + "configdir=s", "cache-dir=s", + "monitor-health", "force-update", "monitor-snapshots", "take-snapshots", "prune-snapshots", "force-prune", "monitor-capacity" ) or pod2usage(2); @@ -41,9 +45,13 @@ my $default_conf_file = "$args{'configdir'}/sanoid.defaults.conf"; # parse config file my %config = init($conf_file,$default_conf_file); +my $cache_dir = $args{'cache-dir'}; + +make_path($cache_dir); + # if we call getsnaps(%config,1) it will forcibly update the cache, TTL or no TTL my $forcecacheupdate = 0; -my $cache = '/var/cache/sanoidsnapshots.txt'; +my $cache = "$cache_dir/snapshots.txt"; my $cacheTTL = 900; # 15 minutes my %snaps = getsnaps( \%config, $cacheTTL, $forcecacheupdate ); my %pruned; @@ -1659,6 +1667,7 @@ Assumes --cron --verbose if no other arguments (other than configdir) are specif Options: --configdir=DIR Specify a directory to find config file sanoid.conf + --cache-dir=DIR Specify a directory to store the zfs snapshot cache --cron Creates snapshots and purges expired snapshots --verbose Prints out additional information during a sanoid run