Permalink
Browse files

prototyped logic for postgresql dump/restore

  • Loading branch information...
lirazsiri committed Sep 8, 2013
1 parent 002eef4 commit 585c1da6bdc2701904c89430694827ed733fc40c
Showing with 59 additions and 0 deletions.
  1. +32 −0 tests/fs2pg.sh
  2. +27 −0 tests/pg2fs.sh
View
@@ -0,0 +1,32 @@
+#!/bin/bash -x
+
+error() {
+ echo "error: $1"
+ exit 1
+}
+
+restoredb() {
+ su postgres -c "dropdb $1"
+
+ cd $1
+ tar c $(cat manifest.txt) 2>/dev/null | \
+ pg_restore --create --format=tar | \
+ #su postgres -c "psql --quiet --echo-all"
+ su postgres -c "psql"
+
+ cd ../
+}
+
+if [ -z "$1" ]; then
+ echo "syntax: $0 path/to/pgfs/"
+ exit 1
+fi
+
+outdir=$1
+cd $outdir
+
+#cat .globals.sql | su postgres -c 'psql -q -o /dev/null'
+cat .globals.sql | su postgres -c 'psql -q -o /dev/null'
+for d in *; do
+ restoredb $d
+done
View
@@ -0,0 +1,27 @@
+#!/bin/bash -x
+
+error() {
+ echo "error: $1"
+ exit 1
+}
+
+dumpdb() {
+ rm -rf $1
+ mkdir -p $1
+ su postgres -c "pg_dump -Ft $1" | tar xvC $1 > $1/manifest.txt
+}
+
+if [ -z "$1" ]; then
+ echo "syntax: $0 path/to/output/"
+ exit 1
+fi
+
+outdir=$1
+mkdir -p $outdir
+cd $outdir
+
+databases=$(su postgres -c 'psql -l' | perl -ne 'if(/^ (\S+?)\s/) { print "$1\n" }' | grep -v template[0-9] | grep -v postgres)
+for database in $databases; do
+ dumpdb $database
+done
+su postgres -c "pg_dumpall --globals" > .globals.sql

0 comments on commit 585c1da

Please sign in to comment.