From 45eb4c9f3ece1d4fc41f2773a98fa951ff5dedc2 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Wed, 13 Nov 2024 19:40:24 -0500 Subject: [PATCH] backups --- .bin/dumpdb.sh | 24 ++++++++++++++++++++++++ .gitignore | 1 + Makefile | 7 +++++++ 3 files changed, 32 insertions(+) create mode 100644 .bin/dumpdb.sh 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 ./...