2 # Copyright (c) 2008, 2009, 2010 Zmanda, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
22 # DF-PATH (Default from PATH): Path to the 'df' binary
23 # ZFS-PATH (Default from PATH): Path to the 'zfs' binary
24 # PFEXEC-PATH (Default from PATH): Path to the 'pfexec' binary
25 # PFEXEC (Default NO): Set to "YES" if you want to use pfexec
27 use lib '@amperldir@';
32 package Amanda::Script::Amzfs_snapshot;
33 use base qw(Amanda::Script Amanda::Application::Zfs);
36 use Amanda::Config qw( :getconf :init );
37 use Amanda::Debug qw( :logging );
38 use Amanda::Util qw( :constants );
40 use Amanda::Constants;
44 my ($execute_where, $config, $host, $disk, $device, $level, $index, $message, $collection, $record, $df_path, $zfs_path, $pfexec_path, $pfexec) = @_;
45 my $self = $class->SUPER::new($execute_where, $config);
47 $self->{execute_where} = $execute_where;
48 $self->{config} = $config;
49 $self->{host} = $host;
51 $self->{disk} = $disk;
53 $self->{disk} = $device;
55 if (defined $device) {
56 $self->{device} = $device;
58 $self->{device} = $disk;
60 $self->{level} = [ @{$level} ]; # Copy the array
61 $self->{index} = $index;
62 $self->{message} = $message;
63 $self->{collection} = $collection;
64 $self->{record} = $record;
65 $self->{df_path} = $df_path;
66 $self->{zfs_path} = $zfs_path;
67 $self->{pfexec_path} = $pfexec_path;
68 $self->{pfexec} = $pfexec;
69 $self->{pfexec_cmd} = undef;
74 sub zfs_snapshot_set_value() {
77 $self->zfs_set_value();
79 if (!defined $self->{device}) {
83 if (!defined $self->{mountpoint}) {
84 $self->print_to_server("$self->{disk} is not a directory", $Amanda::Script_App::ERROR);
95 print "MESSAGE-LINE YES\n";
96 print "MESSAGE-XML NO\n";
97 print "EXECUTE-WHERE YES\n";
100 #define a execute_on_* function for every execute_on you want the script to do
102 sub command_pre_dle_amcheck {
105 $self->zfs_snapshot_set_value();
107 if (!defined $self->{device}) {
111 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
112 if (defined $self->{mountpoint}) {
113 $self->print_to_server("mountpoint $self->{mountpoint}", $Amanda::Script_App::GOOD);
114 $self->print_to_server("directory $self->{directory}", $Amanda::Script_App::GOOD);
115 $self->print_to_server("dir $self->{dir}", $Amanda::Script_App::GOOD);
117 $self->print_to_server("snapshot $self->{snapshot}", $Amanda::Script_App::GOOD);
118 $self->zfs_create_snapshot("check");
119 print "PROPERTY directory $self->{directory}\n";
123 sub command_post_dle_amcheck {
126 $self->zfs_snapshot_set_value();
128 if (!defined $self->{device}) {
132 $self->zfs_destroy_snapshot("check");
135 sub command_pre_dle_estimate {
138 $self->zfs_snapshot_set_value();
139 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
140 $self->zfs_create_snapshot("estimate");
141 print "PROPERTY directory $self->{directory}\n";
145 sub command_post_dle_estimate {
148 $self->zfs_snapshot_set_value();
149 $self->zfs_destroy_snapshot("estimate");
152 sub command_pre_dle_backup {
155 $self->zfs_snapshot_set_value();
156 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
157 $self->zfs_create_snapshot("backup");
158 print "PROPERTY directory $self->{directory}\n";
162 sub command_post_dle_backup {
165 $self->zfs_snapshot_set_value("backup");
166 $self->zfs_destroy_snapshot("backup");
173 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>.
178 my $opt_execute_where;
189 my $zfs_path = 'zfs';
190 my $pfexec_path = 'pfexec';
193 Getopt::Long::Configure(qw{bundling});
195 'execute-where=s' => \$opt_execute_where,
196 'config=s' => \$opt_config,
197 'host=s' => \$opt_host,
198 'disk=s' => \$opt_disk,
199 'device=s' => \$opt_device,
200 'level=s' => \@opt_level,
201 'index=s' => \$opt_index,
202 'message=s' => \$opt_message,
203 'collection=s' => \$opt_collection,
204 'record=s' => \$opt_record,
205 'df-path=s' => \$df_path,
206 'zfs-path=s' => \$zfs_path,
207 'pfexec-path=s' => \$pfexec_path,
208 'pfexec=s' => \$pfexec
211 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);
212 $script->do($ARGV[0]);