~linuxgoose/bocpress

ref: 25a3801b4d2932457cba8762da3febe8de42c5c9 bocpress/ansible/backup-database.sh -rwxr-xr-x 826 bytes
25a3801bJordan Robinson update project files to release 1.3.7 8 days ago
                                                                                
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
27
28
29
30
31
32
33
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
    set -o xtrace
fi

if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
    echo 'Usage: ./backup-database.sh

This script dumps the mataroa postgres database and uploads it into an S3-compatible server.'
    exit
fi

cd "$(dirname "$0")"

main() {
    # source for PGPASSWORD variable if present
    if [ -f /var/www/mataroa/.envrc ]; then
        # shellcheck disable=SC1091
        source /var/www/mataroa/.envrc
    fi

    # dump database in the home folder
    pg_dump -Fc --no-acl mataroa -h localhost -U mataroa -f /home/deploy/mataroa.dump -w

    # upload using aws cli
    /usr/bin/rclone copy --progress /home/deploy/mataroa.dump scaleway:bucket/mataroa-backups/postgres-mataroa-"$(date --utc +%Y%m%d-%H%M%S)"/
}

main "$@"