2 # Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
23 # DF-PATH (Default from PATH): Path to the 'df' binary
24 # ZFS-PATH (Default from PATH): Path to the 'zfs' binary
25 # PFEXEC-PATH (Default from PATH): Path to the 'pfexec' binary
26 # PFEXEC (Default NO): Set to "YES" if you want to use pfexec
28 use lib '@amperldir@';
33 package Amanda::Script::Amzfs_snapshot;
34 use base qw(Amanda::Script Amanda::Application::Zfs);
37 use Amanda::Config qw( :getconf :init );
38 use Amanda::Debug qw( :logging );
39 use Amanda::Util qw( :constants );
41 use Amanda::Constants;
45 my ($execute_where, $config, $host, $disk, $device, $level, $index, $message, $collection, $record, $df_path, $zfs_path, $pfexec_path, $pfexec) = @_;
46 my $self = $class->SUPER::new($execute_where, $config);
48 $self->{execute_where} = $execute_where;
49 $self->{config} = $config;
50 $self->{host} = $host;
52 $self->{disk} = $disk;
54 $self->{disk} = $device;
56 if (defined $device) {
57 $self->{device} = $device;
59 $self->{device} = $disk;
61 $self->{level} = [ @{$level} ]; # Copy the array
62 $self->{index} = $index;
63 $self->{message} = $message;
64 $self->{collection} = $collection;
65 $self->{record} = $record;
66 $self->{df_path} = $df_path;
67 $self->{zfs_path} = $zfs_path;
68 $self->{pfexec_path} = $pfexec_path;
69 $self->{pfexec} = $pfexec;
70 $self->{pfexec_cmd} = undef;
75 sub zfs_snapshot_set_value() {
78 $self->zfs_set_value();
80 if (!defined $self->{device}) {
84 if (!defined $self->{mountpoint}) {
85 $self->print_to_server("$self->{disk} is not a directory", $Amanda::Script_App::ERROR);
96 print "MESSAGE-LINE YES\n";
97 print "MESSAGE-XML NO\n";
98 print "EXECUTE-WHERE YES\n";
101 #define a execute_on_* function for every execute_on you want the script to do
103 sub command_pre_dle_amcheck {
106 $self->zfs_snapshot_set_value();
108 if (!defined $self->{device}) {
112 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
113 if (defined $self->{mountpoint}) {
114 $self->print_to_server("mountpoint $self->{mountpoint}", $Amanda::Script_App::GOOD);
115 $self->print_to_server("directory $self->{directory}", $Amanda::Script_App::GOOD);
116 $self->print_to_server("dir $self->{dir}", $Amanda::Script_App::GOOD);
118 $self->print_to_server("snapshot $self->{snapshot}", $Amanda::Script_App::GOOD);
119 $self->zfs_create_snapshot("check");
120 print "PROPERTY directory $self->{directory}\n";
124 sub command_post_dle_amcheck {
127 $self->zfs_snapshot_set_value();
129 if (!defined $self->{device}) {
133 $self->zfs_destroy_snapshot("check");
136 sub command_pre_dle_estimate {
139 $self->zfs_snapshot_set_value();
140 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
141 $self->zfs_create_snapshot("estimate");
142 print "PROPERTY directory $self->{directory}\n";
146 sub command_post_dle_estimate {
149 $self->zfs_snapshot_set_value();
150 $self->zfs_destroy_snapshot("estimate");
153 sub command_pre_dle_backup {
156 $self->zfs_snapshot_set_value();
157 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
158 $self->zfs_create_snapshot("backup");
159 print "PROPERTY directory $self->{directory}\n";
163 sub command_post_dle_backup {
166 $self->zfs_snapshot_set_value("backup");
167 $self->zfs_destroy_snapshot("backup");
174 Usage: amzfs-snapshot <command> --execute-where=client --config=<config> --host=<host> --disk=<disk> --device=<device> --level=<level> --index=<yes|no> --message=<text> --collection=<no> --record=<yes|no> --df-path=<path/to/df> --zfs-path=<path/to/zfs> --pfexec-path=<path/to/pfexec> --pfexec=<yes|no>.
179 my $opt_execute_where;
190 my $zfs_path = 'zfs';
191 my $pfexec_path = 'pfexec';
194 Getopt::Long::Configure(qw{bundling});
196 'execute-where=s' => \$opt_execute_where,
197 'config=s' => \$opt_config,
198 'host=s' => \$opt_host,
199 'disk=s' => \$opt_disk,
200 'device=s' => \$opt_device,
201 'level=s' => \@opt_level,
202 'index=s' => \$opt_index,
203 'message=s' => \$opt_message,
204 'collection=s' => \$opt_collection,
205 'record=s' => \$opt_record,
206 'df-path=s' => \$df_path,
207 'zfs-path=s' => \$zfs_path,
208 'pfexec-path=s' => \$pfexec_path,
209 'pfexec=s' => \$pfexec
212 my $script = Amanda::Script::Amzfs_snapshot->new($opt_execute_where, $opt_config, $opt_host, $opt_disk, $opt_device, \@opt_level, $opt_index, $opt_message, $opt_collection, $opt_record, $df_path, $zfs_path, $pfexec_path, $pfexec);
213 $script->do($ARGV[0]);