-#!/usr/bin/perl -w
+#!/usr/bin/perl -ws
+# Rudimentary switch parsing. Must be in main package.
+our $cleanup;
+
package BBM;
use strict;
use POSIX qw(setuid setgid);
use File::Temp qw(tempdir);
use File::Path qw(rmtree);
+
# path to Apache HTTPd-style config
my $config = '/etc/bacula/backup-mysql.conf';
my $c = new BBM::Config($config);
my $gid = getgrnam('mysql');
die "Can't find user/group mysql\n" unless $uid or $gid;
+ # CWD could not be accessible for mysql user
+ chdir("/");
+
$) = "$gid $gid";
$( = $gid;
$> = $< = $uid;
# process each cluster
for my $cluster ($c->get('clusters', 'cluster')) {
print ">>> $cluster\n";
- backup_cluster($cluster);
+ if ($cleanup) {
+ cleanup_cluster($cluster);
+ } else {
+ backup_cluster($cluster);
+ }
print "<<< $cluster\n";
}
print "<<<< mysqlhotcopy $database\n";
}
+sub cleanup_cluster {
+ my ($cluster) = @_;
+ my $cluster_dir = "$backup_dir/$cluster";
+ print ">>>> cleanup $cluster_dir\n";
+ rmtree($cluster_dir);
+ print "<<<< cleanup $cluster_dir\n";
+}
+
sub backup_cluster {
my ($cluster) = @_;