File: make_catalog_backup.in

package info (click to toggle)
bacula 7.4.4+dfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 17,084 kB
  • sloc: ansic: 120,922; sh: 22,583; cpp: 15,341; perl: 3,224; makefile: 2,819; sql: 315; awk: 128; xml: 57; python: 43; sed: 16
file content (111 lines) | stat: -rwxr-xr-x 2,643 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
#
# Copyright (C) 2000-2016 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# This script dumps your Bacula catalog in ASCII format
# It works for MySQL, SQLite, and PostgreSQL
#
#  $1 is the name of the database to be backed up and the name
#     of the output file (default = bacula).
#  $2 is the user name with which to access the database
#     (default = bacula).
#  $3 is the password with which to access the database or "" if no password
#     (default ""). WARNING!!! Passing the password via the command line is 
#     insecure and should not be used since any user can display the command 
#     line arguments and the environment using ps.  Please consult your
#     MySQL or PostgreSQL manual for secure methods of specifying the
#     password.
#  $4 is the host on which the database is located
#     (default "")
#  $5 is the type of database
#
#

default_db_type=XX_DBLONGNAME_XX
user=${2:-@db_user@}

#
# See if the fifth argument is a valid backend name.
# If so the user overrides the default database backend.
#
if [ $# -ge 5 ]; then
   case $5 in
     sqlite3)
       db_type=$5
       ;;
     mysql)
       db_type=$5
       ;;
     postgresql)
       db_type=$5
       ;;
     ingres)
       db_type=$5
       ;;
     *)
       ;;
   esac
fi

#
# If no new db_type is gives use the default db_type.
#
if [ -z "${db_type}" ]; then
   db_type="${default_db_type}"
fi

cd @working_dir@
rm -f $1.sql

case ${db_type} in
  sqlite3)
    BINDIR=@SQLITE_BINDIR@
    echo ".dump" | ${BINDIR}/sqlite3 $1.db >$1.sql
    ;;
  mysql)
    BINDIR=@MYSQL_BINDIR@
    if test $# -gt 2; then
      MYSQLPASSWORD=" --password=$3"
    else
      MYSQLPASSWORD=""
    fi
    if test $# -gt 3; then
      MYSQLHOST=" --host=$4"
    else
      MYSQLHOST=""
    fi
    ${BINDIR}/mysqldump -u ${user}${MYSQLPASSWORD}${MYSQLHOST} -f --opt $1 >$1.sql
    ;;
  postgresql)
    BINDIR=@POSTGRESQL_BINDIR@
    if test $# -gt 2; then
      PGPASSWORD=$3
      export PGPASSWORD
    fi
    if test $# -gt 3; then
      PGHOST=" --host=$4"
    else
      PGHOST=""
    fi
    # you could also add --compress for compression.  See man pg_dump
    exec ${BINDIR}/pg_dump -c $PGHOST -U $user $1 >$1.sql
    ;;
esac
#
#  To read back a MySQL database use: 
#     cd @working_dir@
#     rm -f ${BINDIR}/../var/bacula/*
#     mysql <bacula.sql
#
#  To read back a SQLite database use:
#     cd @working_dir@
#     rm -f bacula.db
#     sqlite bacula.db <bacula.sql
#
#  To read back a PostgreSQL database use:
#     cd @working_dir@
#     dropdb bacula
#     createdb bacula -T template0 -E SQL_ASCII
#     psql bacula <bacula.sql
#