]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/make_catalog_backup.in
Add %D option to edit_job_code, simplify callbacks on director side
[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 #  $5 is the type of database
19 #
20 #
21
22 default_db_type=@DEFAULT_DB_TYPE@
23
24 #
25 # See if the fifth argument is a valid backend name.
26 # If so the user overrides the default database backend.
27 #
28 if [ $# -ge 5 ]; then
29    case $5 in
30      sqlite3)
31        db_type=$5
32        ;;
33      mysql)
34        db_type=$5
35        ;;
36      postgresql)
37        db_type=$5
38        ;;
39      ingres)
40        db_type=$5
41        ;;
42      *)
43        ;;
44    esac
45 fi
46
47 #
48 # If no new db_type is gives use the default db_type.
49 #
50 if [ -z "${db_type}" ]; then
51    db_type="${default_db_type}"
52 fi
53
54 cd @working_dir@
55 rm -f $1.sql
56
57 case ${db_type} in
58   sqlite3)
59     BINDIR=@SQLITE_BINDIR@
60     echo ".dump" | ${BINDIR}/sqlite3 $1.db >$1.sql
61     ;;
62   mysql)
63     BINDIR=@MYSQL_BINDIR@
64     if test $# -gt 2; then
65       MYSQLPASSWORD=" --password=$3"
66     else
67       MYSQLPASSWORD=""
68     fi
69     if test $# -gt 3; then
70       MYSQLHOST=" --host=$4"
71     else
72       MYSQLHOST=""
73     fi
74     ${BINDIR}/mysqldump -u ${2}${MYSQLPASSWORD}${MYSQLHOST} -f --opt $1 >$1.sql
75     ;;
76   postgresql)
77     BINDIR=@POSTGRESQL_BINDIR@
78     if test $# -gt 2; then
79       PGPASSWORD=$3
80       export PGPASSWORD
81     fi
82     if test $# -gt 3; then
83       PGHOST=" --host=$4"
84     else
85       PGHOST=""
86     fi
87     # you could also add --compress for compression.  See man pg_dump
88     exec ${BINDIR}/pg_dump -c $PGHOST -U $2 $1 >$1.sql
89     ;;
90 esac
91 #
92 #  To read back a MySQL database use: 
93 #     cd @working_dir@
94 #     rm -f ${BINDIR}/../var/bacula/*
95 #     mysql <bacula.sql
96 #
97 #  To read back a SQLite database use:
98 #     cd @working_dir@
99 #     rm -f bacula.db
100 #     sqlite bacula.db <bacula.sql
101 #
102 #  To read back a PostgreSQL database use:
103 #     cd @working_dir@
104 #     dropdb bacula
105 #     createdb bacula -T template0 -E SQL_ASCII
106 #     psql bacula <bacula.sql
107 #