Commit b8852c35 authored by Boxiang Sun's avatar Boxiang Sun

peertube: improve the postgresql restore script

parent 4d46e1a4
......@@ -14,11 +14,11 @@
# not need these here).
[instance-profile]
filename = instance.cfg.in
md5sum = 9eed4136d9d6f8f855b73bbfefa6397c
md5sum = b67bad9012a8f79c66779d4c660828e2
[instance-peertube]
_update_hash_filename_ = instance-peertube.cfg.in
md5sum = fad859bfcb485a4593a9fb5a89cd665c
md5sum = 45bc81b1659aff57ec763af7863d77db
[template-nginx-service]
filename = template-nginx-service.sh.in
......@@ -51,3 +51,7 @@ md5sum = f1f82101258de19068262b7213fc478b
[template-peertube-backup-script]
filename = template-peertube-backup.sh.in
md5sum = 58d1a4fe246169dea94d7d243b4bac9e
[template-peertube-restore-script]
filename = template-peertube-restore.sh.in
md5sum = 959ed92e4b762127ad0c9955ac21d7b5
......@@ -173,9 +173,8 @@ inline = {{ "${postgresql:pgdata-directory}/**" }}
output = ${directory:srv}/exporter.exclude
[peertube-database-resiliency-after-import-script]
recipe = collective.recipe.template
input = inline: #!/bin/sh
${postgresql:bin}/pg_restore -h ${postgresql:pgdata-directory} -c -U peertube -d peertube_prod ${directory:srv}/backup/peertube_prod-dump.db
recipe = slapos.recipe.template
url = {{ tempalte_peertube_restore }}
output = ${directory:srv}/runner-import-restore
mode = 755
......
......@@ -20,6 +20,7 @@ context =
raw template_peertube_yaml ${template-peertube-yaml:output}
raw template_nginx_configration ${template-nginx-configuration:output}
raw tempalte_peertube_service ${template-peertube-service:output}
raw tempalte_peertube_restore ${template-peertube-restore-script:output}
raw postgresql10_location ${postgresql10:location}
raw tempalte_nginx_service ${template-nginx-service:output}
raw redis_binprefix ${redis28:location}/bin
......
......@@ -131,3 +131,8 @@ output = ${buildout:directory}/${:filename}
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/${:filename}
output = ${buildout:directory}/${:filename}
[template-peertube-restore-script]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/${:filename}
output = ${buildout:directory}/${:filename}
#!${dash-output:dash}
# DO NOT RUN THIS SCRIPT ON PRODUCTION INSTANCE
# OR POSTGRESQL DATA WILL BE ERASED.
# This script will import the dump of the postgresql database to the real
# database. It is launched by the clone (importer) instance of theia
# in the end of the import script.
# Depending on the output, it will create a file containing
# the status of the restoration (success or failure)
# 1. Check the postgresql is running
# > While the server is running, its PID is stored in the file postmaster.pid in the data directory.
# https://www.postgresql.org/docs/current/server-start.html
# which means if the postmaster.pid exist, then the postgresql is running.
pid_file=$${postgresql:pgdata-directory}/postmaster.pid
if [ -e "$pid_file" ]; then
echo "Postgresql pidfile postmaster.pid exits, assuming running. Aborting."
exit 1
fi
# 2.
echo "Deleting existing database..."
find "$${postgresql:pgdata-directory}" -mindepth 1 -delete
# 3.
echo "Starting postgresql..."
$${postgresql:bin}/postgres -D $${postgresql:pgdata-directory}
sleep 30
# If mysql has stopped, abort
if ! [ -d "$${postgresql:pgdata-directory}" ]; then
echo "postgresql exited, aborting."
exit 1
fi
# 4.
echo "Importing data..."
$${postgresql:bin}/pg_restore -h $${postgresql:pgdata-directory} -c -U peertube -d peertube_prod $${directory:srv}/backup/peertube_prod-dump.db
# Check if it failed?
echo 'Backup restoration successfully completed.'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment