archive
This commit is contained in:
38
firefly/postgres/restore.sh
Executable file
38
firefly/postgres/restore.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#! /bin/bash
|
||||
|
||||
skip=${1:-0}
|
||||
set -x
|
||||
set -e
|
||||
backups="$(find /mnt/back/ -maxdepth 1 -mindepth 1 | grep -v '\/\.' | sort -r)"
|
||||
if [ -z "${backups}" ]; then
|
||||
echo "ERR: no backups to restore" >&2
|
||||
exit 0
|
||||
fi
|
||||
tried=0
|
||||
echo Trying backups ${backups}... >&2
|
||||
for lastback in ${backups}; do
|
||||
((tried+=1))
|
||||
if ((tried<=skip)); then
|
||||
continue
|
||||
fi
|
||||
if (
|
||||
echo Trying backup from $lastback >&2
|
||||
set -e
|
||||
service postgresql start
|
||||
psql postgres://ffly:pwd@localhost/fireflyiii < "$lastback"
|
||||
service postgresql start
|
||||
n=0
|
||||
until service postgresql status || ((n>10)); do
|
||||
sleep 5
|
||||
((n+=1))
|
||||
done
|
||||
until service postgresql status | grep -E 'down|online'; do
|
||||
sleep 5
|
||||
done
|
||||
service postgresql status | grep online
|
||||
); then
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
echo "ERR: could not load any backup" >&2
|
||||
exit 1
|
||||
Reference in New Issue
Block a user