home · contact · privacy
Experimental refactor of migration scripts.
[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" ] && [ ! "$1" = "peertube" ]; then
10     echo "Need legal service name (pleroma or peertube)."
11     false
12 fi
13 app="$1"
14 db_name="$2"
15
16 service "${app}" stop
17
18 mv "/home/plom/${app}_backup.tar" /tmp/
19 cd /tmp
20 tar xf "${app}_backup.tar"
21
22 su postgres -c "pg_restore -c -C -d ${db_name} -1 ${app}_backup/${db_name}.pgdump"
23 rm "${app}_backup/${db_name}.pgdump"
24
25 cd "${app}_backup"
26 for path in $/find . -type f); do
27     target_path=$(echo "${path}" | cut -c2-)
28     source_path=$(realpath "${path}")
29     dir=$(dirname "${target_path}")
30     mkdir -p "${dir}"
31     cp -a "${source_path}" "${target_path}"
32 done
33
34 # TODO: Horrible hack, improve.
35 if [ "${app}" = "pleroma" ]; then
36     db_pw=$(cat /etc/pleroma/config.exs | grep password | sed 's/[ ]*password\: *//g' | sed 's/,//g' | sed 's/"//g')
37 elif [ "${app}" = "peertube" ]; then
38     db_pw=$(cat /var/www/peertube/config/production.yaml | grep password | head -1 | sed "s/[ ]*password\: *//g" | sed "s/'//g")
39 fi
40 su postgres -lc "psql -c \"ALTER USER ${app} WITH PASSWORD '${db_pw}';\""
41
42 service "${app}" stop