5 if [ "$#" -lt 2 ]; then
6 echo 'Need two arguments: service name and DB name.'
9 if [ ! "$1" = "pleroma_otp" ] && [ ! "$1" = "pleroma_source" ] && [ ! "$1" = "peertube" ]; then
10 echo "Need legal service name (pleroma_otp or pleroma_source or peertube)."
16 if [ "${app}" = "pleroma_source" ] || [ "${app}" = "pleroma_otp" ]; then
20 service "${service}" stop
22 mv "/home/plom/${service}_backup.tar" /tmp/
24 tar xf "${service}_backup.tar"
26 su postgres -c "pg_restore -c -1 -d ${db_name} ${service}_backup/${db_name}.pgdump"
27 rm "${service}_backup/${db_name}.pgdump"
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
36 target_path=$(echo "${path}" | cut -c2-)
37 source_path=$(realpath "${path}")
38 dir=$(dirname "${target_path}")
40 cp -a "${source_path}" "${target_path}"
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")
49 if [ "${app}" = "pleroma_otp" ] || [ "${app}" = "peertube" ]; then
50 su postgres -lc "psql -c \"ALTER USER ${service} WITH PASSWORD '${db_pw}';\""
53 service "${service}" start