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