2 # Copyright (c) 2008,2009 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@';
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, $config);
46 $self->{execute_where} = $execute_where;
47 $self->{config} = $config;
48 $self->{host} = $host;
50 $self->{disk} = $disk;
52 $self->{disk} = $device;
54 if (defined $device) {
55 $self->{device} = $device;
57 $self->{device} = $disk;
59 $self->{level} = [ @{$level} ]; # Copy the array
60 $self->{index} = $index;
61 $self->{message} = $message;
62 $self->{collection} = $collection;
63 $self->{record} = $record;
64 $self->{df_path} = $df_path;
65 $self->{zfs_path} = $zfs_path;
66 $self->{pfexec_path} = $pfexec_path;
67 $self->{pfexec} = $pfexec;
68 $self->{pfexec_cmd} = undef;
73 sub zfs_snapshot_set_value() {
76 $self->zfs_set_value();
78 if (!defined $self->{device}) {
82 if (!defined $self->{mountpoint}) {
83 $self->print_to_server("$self->{disk} is not a directory", $Amanda::Script_App::ERROR);
94 print "MESSAGE-LINE YES\n";
95 print "MESSAGE-XML NO\n";
96 print "EXECUTE-WHERE YES\n";
99 #define a execute_on_* function for every execute_on you want the script to do
101 sub command_pre_dle_amcheck {
104 $self->zfs_snapshot_set_value();
106 if (!defined $self->{device}) {
110 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
111 if (defined $self->{mountpoint}) {
112 $self->print_to_server("mountpoint $self->{mountpoint}", $Amanda::Script_App::GOOD);
113 $self->print_to_server("directory $self->{directory}", $Amanda::Script_App::GOOD);
114 $self->print_to_server("dir $self->{dir}", $Amanda::Script_App::GOOD);
116 $self->print_to_server("snapshot $self->{snapshot}", $Amanda::Script_App::GOOD);
117 $self->zfs_create_snapshot("check");
118 print "PROPERTY directory $self->{directory}\n";
122 sub command_post_dle_amcheck {
125 $self->zfs_snapshot_set_value();
127 if (!defined $self->{device}) {
131 $self->zfs_destroy_snapshot("check");
134 sub command_pre_dle_estimate {
137 $self->zfs_snapshot_set_value();
138 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
139 $self->zfs_create_snapshot("estimate");
140 print "PROPERTY directory $self->{directory}\n";
144 sub command_post_dle_estimate {
147 $self->zfs_snapshot_set_value();
148 $self->zfs_destroy_snapshot("estimate");
151 sub command_pre_dle_backup {
154 $self->zfs_snapshot_set_value();
155 if ($self->{error_status} == $Amanda::Script_App::GOOD) {
156 $self->zfs_create_snapshot("backup");
157 print "PROPERTY directory $self->{directory}\n";
161 sub command_post_dle_backup {
164 $self->zfs_snapshot_set_value("backup");
165 $self->zfs_destroy_snapshot("backup");
172 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>.
177 my $opt_execute_where;
188 my $zfs_path = 'zfs';
189 my $pfexec_path = 'pfexec';
192 Getopt::Long::Configure(qw{bundling});
194 'execute-where=s' => \$opt_execute_where,
195 'config=s' => \$opt_config,
196 'host=s' => \$opt_host,
197 'disk=s' => \$opt_disk,
198 'device=s' => \$opt_device,
199 'level=s' => \@opt_level,
200 'index=s' => \$opt_index,
201 'message=s' => \$opt_message,
202 'collection=s' => \$opt_collection,
203 'record=s' => \$opt_record,
204 'df-path=s' => \$df_path,
205 'zfs-path=s' => \$zfs_path,
206 'pfexec-path=s' => \$pfexec_path,
207 'pfexec=s' => \$pfexec
210 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);
211 $script->do($ARGV[0]);