2 # Copyright (c) 2005-2008 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 Mathlida 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@';
31 package Amanda::Script::Amzfs_snapshot;
32 use base qw(Amanda::Script Amanda::Application::Zfs);
35 use Amanda::Config qw( :getconf :init );
36 use Amanda::Debug qw( :logging );
37 use Amanda::Util qw( :constants );
39 use Amanda::Constants;
43 my ($execute_where, $config, $host, $disk, $device, $level, $index, $message, $collection, $record, $df_path, $zfs_path, $pfexec_path, $pfexec) = @_;
44 my $self = $class->SUPER::new($execute_where);
46 $self->{execute_where} = $execute_where;
47 $self->{config} = $config;
48 $self->{host} = $host;
49 $self->{disk} = $disk;
50 $self->{device} = $device;
51 $self->{level} = [ @{$level} ]; # Copy the array
52 $self->{index} = $index;
53 $self->{message} = $message;
54 $self->{collection} = $collection;
55 $self->{record} = $record;
56 $self->{df_path} = $df_path;
57 $self->{zfs_path} = $zfs_path;
58 $self->{pfexec_path} = $pfexec_path;
59 $self->{pfexec} = $pfexec;
60 $self->{pfexec_cmd} = undef;
65 sub zfs_snapshot_set_value() {
69 $self->zfs_set_value($action);
71 if (!defined $self->{mountpoint}) {
72 $self->print_to_server($action, "$self->{disk} is not a directory", $Amanda::Script_App::ERROR);
83 print "MESSAGE-LINE YES\n";
84 print "MESSAGE-XML NO\n";
85 print "EXECUTE-WHERE YES\n";
88 #define a execute_on_* function for every execute_on you want the script to do
90 sub command_pre_dle_amcheck {
93 $self->zfs_snapshot_set_value("check");
95 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
96 if (defined $self->{mountpoint}) {
97 $self->print_to_server("check", "mountpoint $self->{mountpoint}", $Amanda::Script_App::GOOD);
98 $self->print_to_server("check", "directory $self->{directory}", $Amanda::Script_App::GOOD);
99 $self->print_to_server("check", "dir $self->{dir}", $Amanda::Script_App::GOOD);
101 $self->print_to_server("check", "snapshot $self->{snapshot}", $Amanda::Script_App::GOOD);
102 $self->zfs_create_snapshot("check");
103 print "PROPERTY directory $self->{directory}\n";
107 sub command_post_dle_amcheck {
110 $self->zfs_snapshot_set_value("check");
111 $self->zfs_destroy_snapshot("check");
114 sub command_pre_dle_estimate {
117 $self->zfs_snapshot_set_value("estimate");
118 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
119 $self->zfs_create_snapshot("estimate");
120 print "PROPERTY directory $self->{directory}\n";
124 sub command_post_dle_estimate {
127 $self->zfs_snapshot_set_value("estimate");
128 $self->zfs_destroy_snapshot("estimate");
131 sub command_pre_dle_backup {
134 $self->zfs_snapshot_set_value("backup");
135 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
136 $self->zfs_create_snapshot("backup");
137 print "PROPERTY directory $self->{directory}\n";
141 sub command_post_dle_backup {
144 $self->zfs_snapshot_set_value("backup");
145 $self->zfs_destroy_snapshot("backup");
152 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>.
157 my $opt_execute_where;
168 my $zfs_path = 'zfs';
169 my $pfexec_path = 'pfexec';
172 Getopt::Long::Configure(qw{bundling});
174 'execute-where=s' => \$opt_execute_where,
175 'config=s' => \$opt_config,
176 'host=s' => \$opt_host,
177 'disk=s' => \$opt_disk,
178 'device=s' => \$opt_device,
179 'level=s' => \@opt_level,
180 'index=s' => \$opt_index,
181 'message=s' => \$opt_message,
182 'collection=s' => \$opt_collection,
183 'record=s' => \$opt_record,
184 'df-path=s' => \$df_path,
185 'zfs-path=s' => \$zfs_path,
186 'pfexec-path=s' => \$pfexec_path,
187 'pfexec=s' => \$pfexec
190 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);
191 $script->do($ARGV[0]);