]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/database/postgresql-dump.txt
Implement RestoreObject for sqlite + cleanups
[bacula/bacula] / bacula / examples / database / postgresql-dump.txt
1 To: bacula-users@lists.sourceforge.net
2 Subject: Re: [Bacula-users] backup postgresql databases
3 From: Valtteri Vuorikoski <vuori@geo0-hel-fi.magenta.net>
4 Date: 11 Mar 2004 14:56:13 +0000
5
6 Mathieu Arnold <mat@mat.cc> writes:
7
8 > I was wondering if someone already had some script, or ways of doings scripts
9 > to backup (and maybe restore) pgsql databases. I'm balancing between taking a
10 > snapshot of the database directory and backuping that, dumping the datas into
11 > .sql.gz files, into .tgz files, or into a pipe letting bacula deal with the
12 > compression.
13
14 Here's a quick shell script hack to dump all databases into separate tars
15 with pg_dump:
16
17 do_pgsql() {
18  mkdir $dump_pg || exit 3
19  psql -Atc 'select datname from pg_database where datistemplate=false' template1 postgres > $dump_pg/databases || exit 4
20
21  touch $dump_pg/dump.log
22  for d in `cat $dump_pg/databases` ; do
23   pg_dump -U postgres -Ft "$d"  > $dump_pg/"$d.tar" >> $dump_pg/dump.log 2>&1
24   [ "$retval" -eq 0 ] && retval=$?
25  done
26 }
27
28 Set the variable dump_pg to point to the directly where you want the dump. Then
29 back it up and delete when you're done.
30
31 You could probably use fs snapshots if you LOCK EXCLUSIVE all tables and CHECKPOINT
32 the transaction log, but as postgresql's relationship between files and tables is
33 not very transparent (such as with mysql), I think particularly partial restores
34 would end up being rather problematic.
35
36 Backup/restore capability does not really appear to be postgresql's
37 forte, unfortunately.
38
39 -- 
40  Valtteri Vuorikoski <vuori@magenta.net>
41  MagentaSites Oy
42