aboutsummaryrefslogtreecommitdiff
path: root/scripts/guix-data-service-backup-database
blob: 77fda89282f30733ce79feb74d31764548f27046 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/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 $$ || true
ionice -p $$ -c 3 || true

pg_dump --format=custom --compress=9 --serializable-deferrable \
        --no-comments \
        --username=guix_data_service \
        --file="$TEMPORARY_FILE_NAME" \
        "$DATABASE_NAME"

mkdir -p "$BACKUP_DIRECTORY/$DATE"

mv "$TEMPORARY_FILE_NAME" "$DESTINATION_FILE_NAME"