3 # Copyright (C) 2000-2016 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
6 # This script dumps your Bacula catalog in ASCII format
7 # It works for MySQL, SQLite, and PostgreSQL
9 # $1 is the name of the database to be backed up and the name
10 # of the output file (default = bacula).
11 # $2 is the user name with which to access the database
13 # $3 is the password with which to access the database or "" if no password
14 # (default ""). WARNING!!! Passing the password via the command line is
15 # insecure and should not be used since any user can display the command
16 # line arguments and the environment using ps. Please consult your
17 # MySQL or PostgreSQL manual for secure methods of specifying the
19 # $4 is the host on which the database is located
21 # $5 is the type of database
25 default_db_type=@DEFAULT_DB_TYPE@
29 # See if the fifth argument is a valid backend name.
30 # If so the user overrides the default database backend.
52 # If no new db_type is gives use the default db_type.
54 if [ -z "${db_type}" ]; then
55 db_type="${default_db_type}"
63 BINDIR=@SQLITE_BINDIR@
64 echo ".dump" | ${BINDIR}/sqlite3 $1.db >$1.sql
68 if test $# -gt 2; then
69 MYSQLPASSWORD=" --password=$3"
73 if test $# -gt 3; then
74 MYSQLHOST=" --host=$4"
78 ${BINDIR}/mysqldump -u ${user}${MYSQLPASSWORD}${MYSQLHOST} -f --opt $1 >$1.sql
81 BINDIR=@POSTGRESQL_BINDIR@
82 if test $# -gt 2; then
86 if test $# -gt 3; then
91 # you could also add --compress for compression. See man pg_dump
92 exec ${BINDIR}/pg_dump -c $PGHOST -U $user $1 >$1.sql
96 # To read back a MySQL database use:
98 # rm -f ${BINDIR}/../var/bacula/*
101 # To read back a SQLite database use:
104 # sqlite bacula.db <bacula.sql
106 # To read back a PostgreSQL database use:
109 # createdb bacula -T template0 -E SQL_ASCII
110 # psql bacula <bacula.sql