]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/database/postgresql-mysql-dump.txt
This revision fixes bug id 0000922
[bacula/bacula] / bacula / examples / database / postgresql-mysql-dump.txt
1 From: Mathieu Arnold <mat@mat.cc>
2 To: bacula-users@lists.sourceforge.net
3 Subject: Re: [Bacula-users] backup postgresql databases
4 Date: Fri, 12 Mar 2004 22:31:58 +0100
5
6 +-Le 11/03/2004 15:20 +0100, Mathieu Arnold a dit :
7 | Hi,
8
9 | I was wondering if someone already had some script, or ways of doings
10 | scripts to backup (and maybe restore) pgsql databases. I'm balancing
11 | between taking a snapshot of the database directory and backuping that,
12 | dumping the datas into .sql.gz files, into .tgz files, or into a pipe
13 | letting bacula deal with the compression.
14
15 | Any ideas ? :)
16
17 Thanks to all ppl I got answers from (many used awfully hard way to get
18 databases), I cooked up my scripts (I needed mysql too), and here they are :
19
20 --------------------------------------------
21 #!/bin/sh
22
23 export TMPDIR="/usr/tmp/"
24 export TEMP="/usr/tmp/"
25 export SAVE="/usr/tmp/dumps/"
26 export LANG="C"
27
28 pg_user=pgsql
29 pg_dbuser=pgsql
30 pg_template=template1
31 exclude=template
32 host=plouf
33
34 sed=/usr/bin/sed
35 pg_dump=/usr/local/bin/pg_dump
36 pg_dumpall=/usr/local/bin/pg_dumpall
37 psql=/usr/local/bin/psql
38
39 gzip="| /usr/bin/gzip -nc9"
40 gzext=".gz"
41
42 if [ ! -d $SAVE ]
43 then
44  mkdir $SAVE
45 else
46  rm -f $SAVE/$host-pgsql*
47 fi
48
49 su - $pg_user -c "$pg_dumpall -g $gzip" > $SAVE/$host-pgsql$gzext
50
51 for i in $($psql -l $pg_template $pg_dbuser|sed -e '1,4d' -e 
52 '/rows)$/,/\eof/d' -e '/template/d' -e 's/ \([^ ]*\).*$/\1/')
53 do
54  su - $pg_user -c "$pg_dump -c -F p $i $gzip" > $SAVE/$host-pgsql-$i$gzext
55 done
56 --------------------------------------------
57
58 For those using complicate selects to get databases list, I advise psql -l
59 :)
60
61 and for mysql :
62
63 --------------------------------------------
64 #!/bin/sh
65
66 export TMPDIR="/usr/tmp/"
67 export TEMP="/usr/tmp/"
68 export SAVE="/usr/tmp/dumps/"
69 export LANG="C"
70
71 my_user=root
72 my_passwd=password
73 host=plouf
74
75 sed=/usr/bin/sed
76 mysql=/usr/local/bin/mysql
77 mysqldump=/usr/local/bin/mysqldump
78
79 gzip="/usr/bin/gzip -nc9"
80 gzext=".gz"
81
82 if [ ! -d $SAVE ]
83 then
84  mkdir $SAVE
85 else
86  rm -f $SAVE/$host-mysql*
87 fi
88
89 for i in $($mysql -u $my_user -p$my_passwd -e 'show databases'|$sed '1d')
90 do
91  $mysqldump -u $my_user -p$my_passwd $i | $gzip > $SAVE/$host-mysql-$i$gzext
92 done
93 --------------------------------------------
94
95 maybe those scripts will save some ppl some time :)
96
97 -- 
98 Mathieu Arnold
99