Line 2... |
Line 2... |
2 |
|
2 |
|
3 |
# snapShot: Manage ZFS snapshots
|
3 |
# snapShot: Manage ZFS snapshots
|
4 |
# see http://wiki.linuxservertech.com for additional information
|
4 |
# see http://wiki.linuxservertech.com for additional information
|
5 |
# Copyright (C) 2022 R. W. Rodolico
|
5 |
# Copyright (C) 2022 R. W. Rodolico
|
6 |
#
|
6 |
#
|
7 |
# version 1.0, 20220423
|
7 |
# version 1.0, 20220423 RWR
|
8 |
# Initial Release
|
8 |
# Initial Release
|
9 |
#
|
9 |
#
|
- |
|
10 |
# version 1.0.1 20220430 RWR
|
- |
|
11 |
# Removed some debugging, set so it will always log the actions to /tmp/snapShot
|
10 |
#
|
12 |
#
|
11 |
# This program is free software: you can redistribute it and/or modify
|
13 |
# This program is free software: you can redistribute it and/or modify
|
12 |
# it under the terms of the GNU General Public License as published by
|
14 |
# it under the terms of the GNU General Public License as published by
|
13 |
# the Free Software Foundation, either version 3 of the License, or
|
15 |
# the Free Software Foundation, either version 3 of the License, or
|
14 |
# (at your option) any later version.
|
16 |
# (at your option) any later version.
|
Line 27... |
Line 29... |
27 |
|
29 |
|
28 |
|
30 |
|
29 |
use strict;
|
31 |
use strict;
|
30 |
use warnings;
|
32 |
use warnings;
|
31 |
|
33 |
|
- |
|
34 |
use version; our $VERSION = version->declare( 'v1.0.1');
|
32 |
use Data::Dumper;
|
35 |
use Data::Dumper;
|
33 |
use Time::Local;
|
36 |
use Time::Local;
|
34 |
use POSIX qw(strftime);
|
37 |
use POSIX qw(strftime);
|
35 |
use YAML::Tiny; # apt-get libyaml-tiny-perl under debian, BSD Systems: cpan -i YAML::Tiny
|
38 |
use YAML::Tiny; # apt-get libyaml-tiny-perl under debian, BSD Systems: cpan -i YAML::Tiny
|
36 |
use Hash::Merge::Simple qw/ merge clone_merge /; # apt install libhash-merge-simple-perl or cpan -i Hash::Merge::Simple
|
39 |
use Hash::Merge::Simple qw/ merge clone_merge /; # apt install libhash-merge-simple-perl or cpan -i Hash::Merge::Simple
|
Line 223... |
Line 226... |
223 |
# everything after that is an ordered list of commands to be executed.
|
226 |
# everything after that is an ordered list of commands to be executed.
|
224 |
# If any command fails, all subsequent commands abort
|
227 |
# If any command fails, all subsequent commands abort
|
225 |
sub run {
|
228 |
sub run {
|
226 |
my $testing = shift;
|
229 |
my $testing = shift;
|
227 |
return 0 unless @_; # bail if there are no commands to run
|
230 |
return 0 unless @_; # bail if there are no commands to run
|
228 |
if ( $testing ) { # don't do it, just dump the commands to /tmp/snapShot
|
231 |
# dump the run to /tmp so the user can see the last one written
|
229 |
open LOG, ">/tmp/snapShot" or die "could not write to /tmp/snapShot: $!\n";
|
232 |
open LOG, ">/tmp/snapShot" or die "could not write to /tmp/snapShot: $!\n";
|
230 |
print LOG join( "\n", @_ ) . "\n";
|
233 |
print LOG join( "\n", @_ ) . "\n";
|
231 |
close LOG;
|
234 |
close LOG;
|
232 |
} else { # actually execute the commands
|
235 |
unless ( $testing ) { # run the commands if we're not testing
|
233 |
my $out; # capture all output
|
236 |
my $out; # capture all output
|
234 |
return 'Not running right now'; # temp while testing
|
- |
|
235 |
while ( my $command = shift ) { # for each command on the stack
|
237 |
while ( my $command = shift ) { # for each command on the stack
|
236 |
$out .= `$command` . "\n"; # add it to $out
|
238 |
$out .= `$command` . "\n"; # add it to $out
|
237 |
if ( $? ) { # we had an error, add debugging text, the end program
|
239 |
if ( $? ) { # we had an error, add debugging text, the end program
|
238 |
$out .= "Error executing command\n\t$command\n\t";
|
240 |
$out .= "Error executing command\n\t$command\n\t";
|
239 |
if ($? == -1) {
|
241 |
if ($? == -1) {
|