diff options
author | Corentin LABBE <clabbe@baylibre.com> | 2020-07-13 13:29:22 +0200 |
---|---|---|
committer | Corentin LABBE <clabbe@baylibre.com> | 2020-07-13 13:36:10 +0200 |
commit | 8c9b84ce25577375d7c0c73229881d6e14a27ee8 (patch) | |
tree | 652298d7f3c7799c335abf7f54fb619cbeca1a7e /lava-master | |
parent | adf3a341befabd3860d90341dd51554fd81d2fbf (diff) |
Do not apply backup twice
If we use persistend_db, a restart with an image containing a backup
will re-apply the backup and so overrun current DB.
So when backup is used, apply a flag to not reuse it.
Diffstat (limited to 'lava-master')
-rwxr-xr-x | lava-master/entrypoint.d/01_setup.sh | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/lava-master/entrypoint.d/01_setup.sh b/lava-master/entrypoint.d/01_setup.sh index 95b180b..e3619f7 100755 --- a/lava-master/entrypoint.d/01_setup.sh +++ b/lava-master/entrypoint.d/01_setup.sh @@ -16,32 +16,37 @@ else sed -i "s,PASSWORD:.*,PASSWORD: '$(cat /root/pg_lava_password)'," /etc/lava-server/settings.d/00-database.yaml || exit $? fi -if [ -e /root/backup/db_lavaserver.gz ];then - gunzip /root/backup/db_lavaserver.gz || exit $? -fi - -if [ -e /root/backup/db_lavaserver ];then - echo "Restore database from backup" - sudo -u postgres psql < /root/backup/db_lavaserver || exit $? - yes yes | lava-server manage migrate || exit $? - echo "Restore jobs output from backup" - rm -r /var/lib/lava-server/default/media/job-output/* +# verify that the backup was not already applied in case of persistent_db +if [ ! -e "/var/lib/postgresql/lava-docker.backup_done" ];then + if [ -e /root/backup/db_lavaserver.gz ];then + gunzip /root/backup/db_lavaserver.gz || exit $? + fi - # allow using different folder for tar operations (/tmp by default) - TMPDIR=${TMPDIR:-/tmp} + if [ -e /root/backup/db_lavaserver ];then + echo "Restore database from backup" + sudo -u postgres psql < /root/backup/db_lavaserver || exit $? + yes yes | lava-server manage migrate || exit $? + echo "Restore jobs output from backup" + rm -r /var/lib/lava-server/default/media/job-output/* - tar xzf /root/backup/joboutput.tar.gz || exit $? -fi - lava-server manage makemigrations - yes yes | lava-server manage migrate || exit $? + # allow using different folder for tar operations (/tmp by default) + TMPDIR=${TMPDIR:-/tmp} -if [ -e /root/backup/devices.tar.gz ];then - echo "INFO: Restoring devices files" - tar xzf /root/backup/devices.tar.gz - chown -R lavaserver:lavaserver /etc/lava-server/dispatcher-config/devices + tar xzf /root/backup/joboutput.tar.gz || exit $? + chown -R lavaserver:lavaserver /var/lib/lava-server/default/media/job-output/ + touch /var/lib/postgresql/lava-docker.backup_done + fi + if [ -e /root/backup/devices.tar.gz ];then + echo "INFO: Restoring devices files" + tar xzf /root/backup/devices.tar.gz + chown -R lavaserver:lavaserver /etc/lava-server/dispatcher-config/devices + fi +else + echo "DEBUG: backup already applied" fi -chown -R lavaserver:lavaserver /var/lib/lava-server/default/media/job-output/ +lava-server manage makemigrations +yes yes | lava-server manage migrate || exit $? # default site is set as example.com if [ -e /root/lava_http_fqdn ];then |