]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/make_catalog_backup.in
Fix segfault when loading Plugins
[bacula/bacula] / bacula / src / cats / make_catalog_backup.in
1 #!/bin/sh
2 #
3 # This script dumps your Bacula catalog in ASCII format
4 # It works for MySQL, SQLite, and PostgreSQL
5 #
6 #  $1 is the name of the database to be backed up and the name
7 #     of the output file (default = bacula).
8 #  $2 is the user name with which to access the database
9 #     (default = bacula).
10 #  $3 is the password with which to access the database or "" if no password
11 #     (default ""). WARNING!!! Passing the password via the command line is 
12 #     insecure and should not be used since any user can display the command 
13 #     line arguments and the environment using ps.  Please consult your
14 #     MySQL or PostgreSQL manual for secure methods of specifying the
15 #     password.
16 #  $4 is the host on which the database is located
17 #     (default "")
18 #
19 #
20 BINDIR=@SQL_BINDIR@
21
22 cd @working_dir@
23 rm -f $1.sql
24 if test xsqlite = x@DB_TYPE@ ; then
25   echo ".dump" | ${BINDIR}/sqlite $1.db >$1.sql
26 else
27   if test xmysql = x@DB_TYPE@ ; then
28     if test $# -gt 2; then
29       MYSQLPASSWORD=" --password=$3"
30     else
31       MYSQLPASSWORD=""
32     fi
33     if test $# -gt 3; then
34       MYSQLHOST=" --host=$4"
35     else
36       MYSQLHOST=""
37     fi
38     ${BINDIR}/mysqldump -u ${2}${MYSQLPASSWORD}${MYSQLHOST} -f --opt $1 >$1.sql
39   else                        
40     if test xpostgresql = x@DB_TYPE@ ; then
41       if test $# -gt 2; then
42         PGPASSWORD=$3
43         export PGPASSWORD
44       fi
45       if test $# -gt 3; then
46         PGHOST=" --host=$4"
47       else
48         PGHOST=""
49       fi
50       # you could also add --compress for compression.  See man pg_dump
51       exec ${BINDIR}/pg_dump -c $PGHOST -U $2 $1 >$1.sql
52     else
53       echo ".dump" | ${BINDIR}/sqlite3 $1.db >$1.sql
54     fi
55   fi
56 fi
57 #
58 #  To read back a MySQL database use: 
59 #     cd @working_dir@
60 #     rm -f ${BINDIR}/../var/bacula/*
61 #     mysql <bacula.sql
62 #
63 #  To read back a SQLite database use:
64 #     cd @working_dir@
65 #     rm -f bacula.db
66 #     sqlite bacula.db <bacula.sql
67 #
68 #  To read back a PostgreSQL database use:
69 #     cd @working_dir@
70 #     dropdb bacula
71 #     createdb bacula -T template0 -E SQL_ASCII
72 #     psql bacula <bacula.sql
73 #