diff --git a/.bin/dumpdb.sh b/.bin/dumpdb.sh new file mode 100644 index 0000000..dcc10db --- /dev/null +++ b/.bin/dumpdb.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +config=config.yaml +pgformat="-Fc" +ext=pgdump + +while getopts ":p" arg; do + case $arg in + c) + config=$OPTARG + ;; + p) + pgformat="-Fp" + ext=sql + ;; + esac +done + +filen=`date "+backups/%Y%m%d_%H%M%S.${ext}"` + +mkdir -p backups/ +dbstring=`yq -r .db.connect "${config}"` +pg_dump "${pgformat}" -f "${filen}" -T calls "${dbstring}" +echo "backed up to ${filen}" diff --git a/.gitignore b/.gitignore index 5c93d4c..cb1321f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ Session.vim *.log *.dlv cover.out +backups/ diff --git a/Makefile b/Makefile index de81f13..997e842 100644 --- a/Makefile +++ b/Makefile @@ -35,5 +35,12 @@ coverage-html: coverage: go test -coverprofile cover.out +# backup backs up the database without calls +backup: + sh .bin/dumpdb.sh + +backupplain: + sh .bin/dumpdb.sh -p + test: go test -v ./...