This repository has been archived by the owner on Nov 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbmanage.def
36 lines (28 loc) · 1.66 KB
/
dbmanage.def
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
34
35
36
########################################################################
# Example usage
#
# To create backup
# singularity run --env AUTOREDUCTION_PRODUCTION=1 --env AUTOREDUCE_DB_PASSPHRASE=apples --bind ../autoreduce:/autoreduce/ --app backup dbmanage.sif
#
# To restore backup - the last parameter is the encrypted file produced by --app backup
# singularity run --env AUTOREDUCTION_PRODUCTION=1 --env AUTOREDUCE_DB_PASSPHRASE=apples --bind ../autoreduce:/autoreduce/ --app restore dbmanage.sif backup_2021-04-10T16:16:59+00:00_django.db.backends.sqlite3_sqlite3.db.json.gpg
#
########################################################################
Bootstrap: docker-daemon
From: autoreduction/webapp:latest
Includecmd: no
%apprun backup
[ -z "$AUTOREDUCE_DB_PASSPHRASE" ] && echo "Provide AUTOREDUCE_DB_PASSPHRASE value with --env AUTOREDUCE_DB_PASSPHRASE=" && exit 1
DB_FILENAME_PREFIX=`autoreduce-webapp-manage shell -c \
"import os; from django.db import connection; print(connection.settings_dict['ENGINE'], os.path.basename(connection.settings_dict['NAME']),sep='_')"`
name=backup_$(date --utc -I'seconds')_"$DB_FILENAME_PREFIX".json
echo Output file will be "$name"
autoreduce-webapp-manage dumpdata --natural-foreign --natural-primary -e contenttypes -e auth.Permission > $name
echo Encrypting "$name"
gpg --passphrase $AUTOREDUCE_DB_PASSPHRASE --quiet --batch --yes -c $name
echo Saved "$name.gpg" and removing unencrypted file
rm $name
%apprun restore
gpg --passphrase $AUTOREDUCE_DB_PASSPHRASE --quiet --batch --yes "$@"
# %.* removes the last extension - which should be .gpg
autoreduce-webapp-manage loaddata "${@%.*}"