home · contact · privacy
In /etc/hosts-setting script, ignore IPv6s.
[config] / buster / setup_scripts / restore_app.sh
1 #!/bin/sh
2 set -e
3 set -x
4
5 if [ "$#" -lt 2 ]; then
6     echo 'Need two arguments: service name and DB name.'
7     false
8 fi
9 if [ ! "$1" = "pleroma_otp" ] && [ ! "$1" = "pleroma_source" ] && [ ! "$1" = "peertube" ]; then
10     echo "Need legal service name (pleroma_otp or pleroma_source or peertube)."
11     false
12 fi
13 app="$1"
14 db_name="$2"
15 service="$1"
16 if [ "${app}" = "pleroma_source" ] || [ "${app}" = "pleroma_otp" ]; then
17     service=pleroma
18 fi
19
20 service "${service}" stop
21
22 mv "/home/plom/${service}_backup.tar" /tmp/
23 cd /tmp
24 tar xf "${service}_backup.tar"
25
26 su postgres -c "pg_restore -c -1 -d ${db_name} ${service}_backup/${db_name}.pgdump"
27 rm "${service}_backup/${db_name}.pgdump"
28
29 cd "${service}_backup"
30 for path in $(find . -type f); do
31     if [ "${app}" = "pleroma_source" ]; then
32         if [ "${path}" = './opt/pleroma/config/prod.secret.exs' ]; then
33             continue  # skip file that contains passwords
34         fi
35     fi
36     target_path=$(echo "${path}" | cut -c2-)
37     source_path=$(realpath "${path}")
38     dir=$(dirname "${target_path}")
39     mkdir -p "${dir}"
40     cp -a "${source_path}" "${target_path}"
41 done
42
43 # TODO: Horrible hack, improve.
44 if [ "${app}" = "pleroma_otp" ]; then
45     db_pw=$(cat /etc/pleroma/config.exs | grep password | sed 's/[ ]*password\: *//g' | sed 's/,//g' | sed 's/"//g')
46 elif [ "${app}" = "peertube" ]; then
47     db_pw=$(cat /var/www/peertube/config/production.yaml | grep password | head -1 | sed "s/[ ]*password\: *//g" | sed "s/'//g")
48 fi
49 if [ "${app}" = "pleroma_otp" ] || [ "${app}" = "peertube" ]; then
50     su postgres -lc "psql -c \"ALTER USER ${service} WITH PASSWORD '${db_pw}';\""
51 fi
52
53 service "${service}" start