aboutsummaryrefslogtreecommitdiff
path: root/scripts/guix-data-service-backup-database
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-03-02 21:44:29 +0000
committerChristopher Baines <mail@cbaines.net>2020-03-02 21:44:29 +0000
commit77caafb019047a8e274e6d587e31d58854c7b79f (patch)
tree8255bad94fb629303ca0d80b8a1ae0f5066c0803 /scripts/guix-data-service-backup-database
parentc407f55c846e298be59dad53850892b04324cab3 (diff)
downloaddata-service-77caafb019047a8e274e6d587e31d58854c7b79f.tar
data-service-77caafb019047a8e274e6d587e31d58854c7b79f.tar.gz
Add scripts for generating database dumps
Diffstat (limited to 'scripts/guix-data-service-backup-database')
-rwxr-xr-xscripts/guix-data-service-backup-database25
1 files changed, 25 insertions, 0 deletions
diff --git a/scripts/guix-data-service-backup-database b/scripts/guix-data-service-backup-database
new file mode 100755
index 0000000..365f78c
--- /dev/null
+++ b/scripts/guix-data-service-backup-database
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+set -eux
+
+DATABASE_NAME=guix_data_service
+DEFAULT_BACKUP_DIRECTORY="/var/lib/guix-data-service/dumps"
+BACKUP_DIRECTORY="${GUIX_DATA_SERVICE_BACKUP_DIRECTORY:-$DEFAULT_BACKUP_DIRECTORY}"
+
+DATE="$(date "+%Y-%m-%d")"
+
+FULL_BACKUP_NAME="guix_data_service_full.dump"
+TEMPORARY_FILE_NAME="${TMPDIR:-/tmp}/guix_data_service_full-$DATE.dump.tmp"
+DESTINATION_FILE_NAME="$BACKUP_DIRECTORY/$DATE/$FULL_BACKUP_NAME"
+
+renice 19 -p $$
+ionice -p $$ -c 3
+
+pg_dump --format=custom --compress=9 --serializable-deferrable \
+ --username=guix_data_service \
+ --file="$TEMPORARY_FILE_NAME" \
+ "$DATABASE_NAME"
+
+mkdir -p "$BACKUP_DIRECTORY/$DATE"
+
+mv "$TEMPORARY_FILE_NAME" "$DESTINATION_FILE_NAME"