aboutsummaryrefslogtreecommitdiff
path: root/files/bin/fiken-dump-database
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2014-08-23 17:31:41 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2014-08-23 17:31:41 +0200
commit5b1cc7e49adeb7c6060f04fda0a667e3e17809ab (patch)
tree0d686367329a97992f9a80d9a960c75890d1e68a /files/bin/fiken-dump-database
downloadfiken-ansible-5b1cc7e49adeb7c6060f04fda0a667e3e17809ab.tar.gz
fiken-ansible-5b1cc7e49adeb7c6060f04fda0a667e3e17809ab.tar.bz2
fiken-ansible-5b1cc7e49adeb7c6060f04fda0a667e3e17809ab.tar.xz
fiken-ansible-5b1cc7e49adeb7c6060f04fda0a667e3e17809ab.zip
wip
Diffstat (limited to 'files/bin/fiken-dump-database')
-rw-r--r--files/bin/fiken-dump-database40
1 files changed, 40 insertions, 0 deletions
diff --git a/files/bin/fiken-dump-database b/files/bin/fiken-dump-database
new file mode 100644
index 0000000..eb962d7
--- /dev/null
+++ b/files/bin/fiken-dump-database
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+export BUP_DIR=$HOME/bups/postgres-backup
+
+now=`date -u +%Y-%m-%dT%H:%M:%S.000Z`
+
+db="$1"
+
+if [[ -z $db ]]
+then
+ echo "usage: $0 <database>"
+ exit 1
+fi
+
+dir="$HOME/backups/${db}"
+name="pg_${db}_${now}.backup"
+path="$dir/$name"
+
+mkdir -p "$dir"
+
+echo "Dumping $db to $path"
+
+time pg_dump -h localhost -U fiken-prod -b -Fc $db > $path
+rm -rf "$dir/latest"
+ln -s "$name" "$dir/latest"
+
+echo "Updating backups"
+(
+cd "$dir"
+bup index -u .
+bup save -n postgres-backup .
+)
+
+echo "Dump complete"
+echo "File size:" `ls -sh $path|cut -f 1 -d " "`
+echo ""
+echo "To restore to a db:"
+echo "psql -1 -h localhost -U fiken-dev -d fiken-dev -c 'drop schema public CASCADE; create schema public'"
+echo "vacuumlo -U fiken-dev -h localhost -v -l 10000 fiken-dev"
+echo "pg_restore -O -U fiken-dev -h localhost -d fiken-dev" $name