]> git.sur5r.net Git - bacula/bacula/commitdiff
Add make_catalog_backup.pl script that uses env variables and
authorEric Bollengier <eric@eb.homelinux.org>
Wed, 6 Jan 2010 09:15:56 +0000 (10:15 +0100)
committerEric Bollengier <eric@eb.homelinux.org>
Wed, 6 Jan 2010 09:15:56 +0000 (10:15 +0100)
disk file to pass database password for backup

bacula/autoconf/configure.in
bacula/configure
bacula/scripts/make_catalog_backup.pl.in [new file with mode: 0644]

index 25a490521962bf587041394dca7899eebc24bc5f..c6e331e25c866fb9bf3d5df51676fe9dd161b117 100644 (file)
@@ -2978,6 +2978,7 @@ AC_OUTPUT([autoconf/Make.common \
           scripts/bat.desktop.xsu \
           scripts/bat.desktop.consolehelper \
           scripts/bat.console_apps \
+           scripts/make_catalog_backup.pl \
           src/Makefile \
           src/host.h \
           src/console/Makefile \
@@ -3091,7 +3092,7 @@ cd ${BUILD_DIR}
 
 cd scripts
 chmod 755 startmysql stopmysql bacula startit stopit btraceback mtx-changer
-chmod 755 dvd-handler dvd-simulator
+chmod 755 dvd-handler dvd-simulator make_catalog_backup.pl
 chmod 755 bconsole gconsole mtx-changer devel_bacula logrotate
 cd ..
 
index 089ebe6c0bed4c8b0c1c1c06994034590fd09db7..a834afc95429f68608a1e57db5f5c28333eecd93 100755 (executable)
@@ -29124,7 +29124,7 @@ if test "x${subsysdir}" = "x${sbindir}" ; then
    exit 1
 fi
 
-ac_config_files="$ac_config_files autoconf/Make.common Makefile manpages/Makefile scripts/startmysql scripts/stopmysql scripts/btraceback scripts/startit scripts/stopit scripts/bconsole scripts/gconsole scripts/bacula scripts/bacula-ctl-dir scripts/bacula-ctl-fd scripts/bacula-ctl-sd scripts/devel_bacula scripts/Makefile scripts/logrotate scripts/bacula.desktop.gnome1 scripts/bacula.desktop.gnome2 scripts/bacula.desktop.gnome1.consolehelper scripts/bacula.desktop.gnome2.consolehelper scripts/bacula.desktop.gnome1.xsu scripts/bacula.desktop.gnome2.xsu scripts/bgnome-console.console_apps scripts/mtx-changer scripts/disk-changer scripts/dvd-handler scripts/dvd-simulator scripts/bacula-tray-monitor.desktop scripts/logwatch/Makefile scripts/logwatch/logfile.bacula.conf scripts/wxconsole.console_apps scripts/wxconsole.desktop.consolehelper scripts/wxconsole.desktop.xsu scripts/bat.desktop scripts/bat.desktop.xsu scripts/bat.desktop.consolehelper scripts/bat.console_apps src/Makefile src/host.h src/console/Makefile src/console/bconsole.conf src/qt-console/bat.conf src/qt-console/bat.pro src/qt-console/bat.pro.mingw32 src/qt-console/install_conf_file src/wx-console/Makefile src/wx-console/bwx-console.conf src/tray-monitor/Makefile src/tray-monitor/tray-monitor.conf src/dird/Makefile src/dird/bacula-dir.conf src/lib/Makefile src/stored/Makefile src/stored/bacula-sd.conf src/filed/Makefile src/filed/bacula-fd.conf src/cats/Makefile src/cats/make_catalog_backup src/cats/delete_catalog_backup src/cats/create_postgresql_database src/cats/update_postgresql_tables src/cats/make_postgresql_tables src/cats/grant_postgresql_privileges src/cats/drop_postgresql_tables src/cats/drop_postgresql_database src/cats/create_mysql_database src/cats/update_mysql_tables src/cats/make_mysql_tables src/cats/grant_mysql_privileges src/cats/drop_mysql_tables src/cats/drop_mysql_database src/cats/create_sqlite3_database src/cats/update_sqlite3_tables src/cats/make_sqlite3_tables src/cats/grant_sqlite3_privileges src/cats/drop_sqlite3_tables src/cats/drop_sqlite3_database src/cats/create_ingres_database src/cats/update_ingres_tables src/cats/make_ingres_tables src/cats/grant_ingres_privileges src/cats/drop_ingres_tables src/cats/drop_ingres_database src/cats/sqlite src/cats/mysql src/cats/create_bdb_database src/cats/update_bdb_tables src/cats/make_bdb_tables src/cats/grant_bdb_privileges src/cats/drop_bdb_tables src/cats/drop_bdb_database src/cats/create_bacula_database src/cats/update_bacula_tables src/cats/grant_bacula_privileges src/cats/make_bacula_tables src/cats/drop_bacula_tables src/cats/drop_bacula_database src/findlib/Makefile src/tools/Makefile src/plugins/fd/Makefile src/plugins/sd/Makefile src/plugins/dir/Makefile src/win32/Makefile.inc po/Makefile.in updatedb/update_mysql_tables_9_to_10 updatedb/update_sqlite3_tables_9_to_10 updatedb/update_postgresql_tables_9_to_10 updatedb/update_mysql_tables_10_to_11 updatedb/update_sqlite3_tables_10_to_11 updatedb/update_postgresql_tables_10_to_11 examples/nagios/check_bacula/Makefile $PFILES"
+ac_config_files="$ac_config_files autoconf/Make.common Makefile manpages/Makefile scripts/startmysql scripts/stopmysql scripts/btraceback scripts/startit scripts/stopit scripts/bconsole scripts/gconsole scripts/bacula scripts/bacula-ctl-dir scripts/bacula-ctl-fd scripts/bacula-ctl-sd scripts/devel_bacula scripts/Makefile scripts/logrotate scripts/bacula.desktop.gnome1 scripts/bacula.desktop.gnome2 scripts/bacula.desktop.gnome1.consolehelper scripts/bacula.desktop.gnome2.consolehelper scripts/bacula.desktop.gnome1.xsu scripts/bacula.desktop.gnome2.xsu scripts/bgnome-console.console_apps scripts/mtx-changer scripts/disk-changer scripts/dvd-handler scripts/dvd-simulator scripts/bacula-tray-monitor.desktop scripts/logwatch/Makefile scripts/logwatch/logfile.bacula.conf scripts/wxconsole.console_apps scripts/wxconsole.desktop.consolehelper scripts/wxconsole.desktop.xsu scripts/bat.desktop scripts/bat.desktop.xsu scripts/bat.desktop.consolehelper scripts/bat.console_apps scripts/make_catalog_backup.pl src/Makefile src/host.h src/console/Makefile src/console/bconsole.conf src/qt-console/bat.conf src/qt-console/bat.pro src/qt-console/bat.pro.mingw32 src/qt-console/install_conf_file src/wx-console/Makefile src/wx-console/bwx-console.conf src/tray-monitor/Makefile src/tray-monitor/tray-monitor.conf src/dird/Makefile src/dird/bacula-dir.conf src/lib/Makefile src/stored/Makefile src/stored/bacula-sd.conf src/filed/Makefile src/filed/bacula-fd.conf src/cats/Makefile src/cats/make_catalog_backup src/cats/delete_catalog_backup src/cats/create_postgresql_database src/cats/update_postgresql_tables src/cats/make_postgresql_tables src/cats/grant_postgresql_privileges src/cats/drop_postgresql_tables src/cats/drop_postgresql_database src/cats/create_mysql_database src/cats/update_mysql_tables src/cats/make_mysql_tables src/cats/grant_mysql_privileges src/cats/drop_mysql_tables src/cats/drop_mysql_database src/cats/create_sqlite3_database src/cats/update_sqlite3_tables src/cats/make_sqlite3_tables src/cats/grant_sqlite3_privileges src/cats/drop_sqlite3_tables src/cats/drop_sqlite3_database src/cats/create_ingres_database src/cats/update_ingres_tables src/cats/make_ingres_tables src/cats/grant_ingres_privileges src/cats/drop_ingres_tables src/cats/drop_ingres_database src/cats/sqlite src/cats/mysql src/cats/create_bdb_database src/cats/update_bdb_tables src/cats/make_bdb_tables src/cats/grant_bdb_privileges src/cats/drop_bdb_tables src/cats/drop_bdb_database src/cats/create_bacula_database src/cats/update_bacula_tables src/cats/grant_bacula_privileges src/cats/make_bacula_tables src/cats/drop_bacula_tables src/cats/drop_bacula_database src/findlib/Makefile src/tools/Makefile src/plugins/fd/Makefile src/plugins/sd/Makefile src/plugins/dir/Makefile src/win32/Makefile.inc po/Makefile.in updatedb/update_mysql_tables_9_to_10 updatedb/update_sqlite3_tables_9_to_10 updatedb/update_postgresql_tables_9_to_10 updatedb/update_mysql_tables_10_to_11 updatedb/update_sqlite3_tables_10_to_11 updatedb/update_postgresql_tables_10_to_11 examples/nagios/check_bacula/Makefile $PFILES"
 
 ac_config_commands="$ac_config_commands default"
 
@@ -30219,6 +30219,7 @@ do
     "scripts/bat.desktop.xsu") CONFIG_FILES="$CONFIG_FILES scripts/bat.desktop.xsu" ;;
     "scripts/bat.desktop.consolehelper") CONFIG_FILES="$CONFIG_FILES scripts/bat.desktop.consolehelper" ;;
     "scripts/bat.console_apps") CONFIG_FILES="$CONFIG_FILES scripts/bat.console_apps" ;;
+    "scripts/make_catalog_backup.pl") CONFIG_FILES="$CONFIG_FILES scripts/make_catalog_backup.pl" ;;
     "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
     "src/host.h") CONFIG_FILES="$CONFIG_FILES src/host.h" ;;
     "src/console/Makefile") CONFIG_FILES="$CONFIG_FILES src/console/Makefile" ;;
@@ -31864,7 +31865,7 @@ cd ${BUILD_DIR}
 
 cd scripts
 chmod 755 startmysql stopmysql bacula startit stopit btraceback mtx-changer
-chmod 755 dvd-handler dvd-simulator breload make_catalog_backup.pl
+chmod 755 dvd-handler dvd-simulator make_catalog_backup.pl
 chmod 755 bconsole gconsole mtx-changer devel_bacula logrotate
 cd ..
 
diff --git a/bacula/scripts/make_catalog_backup.pl.in b/bacula/scripts/make_catalog_backup.pl.in
new file mode 100644 (file)
index 0000000..f3efec2
--- /dev/null
@@ -0,0 +1,160 @@
+#!/usr/bin/env perl
+use strict;
+
+=head1 SCRIPT
+
+  This script dumps your Bacula catalog in ASCII format
+  It works for MySQL, SQLite, and PostgreSQL
+
+=head1 USAGE
+
+    make_catalog_backup.pl MyCatalog
+
+=head1 LICENSE
+
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
+
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of Kern Sibbald.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
+   Switzerland, email:ftf@fsfeurope.org.
+
+=cut
+
+$ENV{PATH}="@SQL_BINDIR@:$ENV{PATH}";
+
+my $cat = shift or die "Usage: $0 catalogname";
+my $dir_conf='@sbindir@/dbcheck -B -c @sysconfdir@/bacula-dir.conf';
+my $wd = "@working_dir@";
+
+sub dump_sqlite
+{
+    my %args = @_;
+
+    exec("echo .dump | sqlite '$wd/$args{db_name}.db' > '$wd/$args{db_name}.sql'");
+    print "Error while executing sqlite dump $!\n";
+    return 1;
+}
+
+sub dump_sqlite3
+{
+    my %args = @_;
+
+    exec("echo .dump | sqlite3 '$wd/$args{db_name}.db' > '$wd/$args{db_name}.sql'");
+    print "Error while executing sqlite dump $!\n";
+    return 1;
+}
+
+# TODO: use just ENV and drop the pg_service.conf file
+sub dump_pgsql
+{
+    my %args = @_;
+    umask(0077);
+
+    if ($args{db_address}) {
+        $ENV{PGHOST}=$args{db_address};
+    }
+    if ($args{db_port}) {
+        $ENV{PGPORT}=$args{db_port};
+    }
+
+    $ENV{PGDATABASE}=$args{db_name};
+    $ENV{PGUSER}=$args{db_user};
+    $ENV{PGPASSWORD}=$args{db_password};
+    exec("HOME='$wd' pg_dump -c > '$wd/$args{db_name}.sql'");
+    print "Error while executing postgres dump $!\n";
+    return 1;               # in case of error
+}
+
+sub dump_mysql
+{
+    my %args = @_;
+    umask(0700);
+    unlink("$wd/.my.cnf");
+    open(MY, ">$wd/.my.cnf") 
+        or die "Can't open $wd/.my.cnf for writing $@";
+    $args{db_address} = $args{db_address} || "localhost";
+    print MY "[client]
+host=$args{db_address}
+user=$args{db_user}
+password=$args{db_password}
+";
+    if ($args{db_port}) {
+        print MY "port=%args{db_port}\n";
+    }
+    
+    close(MY);
+
+    exec("HOME='$wd' mysqldump -f --opt $args{db_name} > '$wd/$args{db_name}.sql'");
+    print "Error while executing mysql dump $!\n";
+    return 1;
+}
+
+sub dump_catalog
+{
+    my %args = @_;
+    if ($args{db_type} eq 'SQLite') {
+        dump_sqlite(%args);
+    } elsif ($args{db_type} eq 'SQLite3') {
+        dump_sqlite3(%args);
+    } elsif ($args{db_type} eq 'PostgreSQL') {
+        dump_pgsql(%args);
+    } elsif ($args{db_type} eq 'MySQL') {
+        dump_mysql(%args);
+    } else {
+        die "This database type isn't supported";
+    }
+}
+
+open(FP, "$dir_conf|") or die "Can't get catalog information $@";
+# catalog=MyCatalog
+# db_type=SQLite
+# db_name=regress
+# db_driver=
+# db_user=regress
+# db_password=
+# db_address=
+# db_port=0
+# db_socket=
+my %cfg;
+
+while(my $l = <FP>)
+{
+    if ($l =~ /catalog=(.+)/) {
+        if (exists $cfg{catalog} and $cfg{catalog} eq $cat) {
+            exit dump_catalog(%cfg);
+        }
+        %cfg = ();              # reset
+    }
+
+    if ($l =~ /(\w+)=(.+)/) {
+        $cfg{$1}=$2;
+    }
+}
+
+if (exists $cfg{catalog} and $cfg{catalog} eq $cat) {
+    exit dump_catalog(%cfg);
+}
+
+print "Can't find your catalog ($cat) in director configuration\n";
+exit 1;