Commit 7e8428fc authored by Boxiang Sun's avatar Boxiang Sun

peertube: restore fixup

parent f2f15bb6
......@@ -54,4 +54,4 @@ md5sum = 58d1a4fe246169dea94d7d243b4bac9e
[template-peertube-restore-script]
filename = template-peertube-restore.sh.in
md5sum = 75f8ddfe15d087294dece94029417193
md5sum = ad91e27d140d96277144e5ba83b553df
......@@ -11,32 +11,30 @@
# 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
die() {
echo "$*" 1>&2
exit 1
}
if [ -e "$pid_file" ]; then
echo "Postgresql pidfile postmaster.pid exits, assuming running. Aborting."
exit 1
fi
pg_version=$${postgresql:pgdata-directory}/PG_VERSION
# 2. Restore database
$${postgresql:bin}/pg_restore -h $${postgresql:pgdata-directory} --exit-on-error -c -d peertube_prod -U peertube $${directory:srv}/backup/peertube_prod-dump.db
tpgwait=60
while ! [ -e "$pg_version" ]; do
tpgwait=$(( $tpgwait - 1 ))
test $tpgwait = 0 && die "PGdata directory not ready"
echo "I: PGdata directory is not ready (yet ?); will retry $tpgwait times..." 1>&2
sleep 1
done
# 3.
# # 2.
echo "Starting postgresql..."
$${postgresql:bin}/psql -D $${postgresql:pgdata-directory}
$${postgresql:bin}/postgres -D $${postgresql:pgdata-directory} &
die() {
echo "$*" 1>&2
exit 1
}
postgres_pid=$!
echo $postgres_pid
# run psql on gitlab db
# run psql
psql() {
$${postgresql:bin}/psql \
-h $${postgresql:pgdata-directory} \
......@@ -57,12 +55,26 @@ while true; do
done
echo "I: PostgreSQL ready." 1>&2
$${postgresql:bin}/postgres -D $${postgresql:pgdata-directory}
sleep 30
# If postgresql has stopped, abort
if ! [ -d "$${postgresql:pgdata-directory}" ]; then
sleep 5
# Check the postgresql is running, if postgresql has stopped, abort
# > 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 exited, aborting."
exit 1
fi
$${postgresql:bin}/pg_restore -h $${postgresql:pgdata-directory} -U peertube -e -c -C -d postgres $${directory:srv}/backup/peertube_prod-dump.db
pg_restore_pid=$!
echo $pg_restore_pid
wait $PID
echo 'Backup restoration successfully completed.'
# Allow slapos node instance to start the postgresql service
kill $postgres_pid
\ No newline at end of file
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