diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-02-01 19:25:41 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-02-01 19:25:41 +0100 |
| commit | 69a416caa2bce3dc4a3aff61fb8ae955f7561e51 (patch) | |
| tree | 7f80e7f3143872c2e0a8867399abfcd35c9d5dbc /scripts/backup/postgres_backup_v1.sh | |
| parent | fdee7340ac18b0866abf0c44643f4c937fc4cf80 (diff) | |
| download | dotfiles-server-69a416caa2bce3dc4a3aff61fb8ae955f7561e51.tar.xz dotfiles-server-69a416caa2bce3dc4a3aff61fb8ae955f7561e51.zip | |
Reorganise scripts
Diffstat (limited to 'scripts/backup/postgres_backup_v1.sh')
| -rwxr-xr-x | scripts/backup/postgres_backup_v1.sh | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/backup/postgres_backup_v1.sh b/scripts/backup/postgres_backup_v1.sh new file mode 100755 index 0000000..10f3b30 --- /dev/null +++ b/scripts/backup/postgres_backup_v1.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -Eeuo pipefail + +host="localhost" +port="5432" +user="postgres" +databases=("vsh_store" "time_tracker") +backup_name=$(date -u +%Y%m%dT%H%M%SZ) +backup_folder=/opt/backup/db + +for i in "${databases[@]}" +do + + pushd $backup_folder + + if [ ! -d "$i" ]; then + mkdir -p $i + fi + + cd $i + + echo "$(date -u +%Y-%m-%d_%H:%M:%SZ) Dumping $i into $backup_folder/$i/$backup_name.psql" + pg_dump -U $user -p $port -h $host -Fc --clean --if-exists $i -f $backup_name.psql + + echo "$(date -u +%Y-%m-%d_%H:%M:%SZ) Dumping $i into $backup_folder/$i/$backup_name.sql" + pg_dump -U $user -p $port -h $host --inserts --clean --if-exists $i -f $backup_name.sql + + popd + +done |
