diff options
-rw-r--r-- | README.md | 11 | ||||
-rwxr-xr-x | backup.sh | 22 | ||||
-rw-r--r-- | lava-master/Dockerfile | 2 | ||||
-rw-r--r-- | lava-master/backup/.empty | 0 | ||||
-rwxr-xr-x | lava-master/scripts/setup.sh | 14 |
5 files changed, 49 insertions, 0 deletions
@@ -322,6 +322,17 @@ For the moment, it is unsupported and unbuilded. ## Backporting LAVA patches All upstream LAVA patches could be backported by placing them in lava-master/lava-patch/ +## Backups / restore +For backupping a running docker, the "backup.sh" script could be used. +It will store boards.yaml + postgresql database backup + joboutputs. + +For restoring a backup, postgresql database backup + joboutputs must be copied in master backup directory before build. + +Example: +./backup.sh +This produce a backup-20180704_1206 directory +For restoring this backup, simply cp backup-20180704_1206/* output/local/master/backup/ + ## Security Note that this container provides defaults which are unsecure. If you plan on deploying this in a production enviroment please consider the following items: diff --git a/backup.sh b/backup.sh new file mode 100755 index 0000000..f803486 --- /dev/null +++ b/backup.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +BACKUP_DIR="backup-$(date +%Y%m%d_%H%M)" + +mkdir $BACKUP_DIR +cp boards.yaml $BACKUP_DIR + +DOCKERID=$(docker ps |grep master | cut -d' ' -f1) +if [ -z "$DOCKERID" ];then + exit 1 +fi +# for an unknown reason pg_dump > file doesnt work +docker exec -ti $DOCKERID sudo -u postgres pg_dump --create --clean lavaserver --file /tmp/db_lavaserver || exit $? +docker exec -ti $DOCKERID gzip /tmp/db_lavaserver || exit $? +docker cp $DOCKERID:/tmp/db_lavaserver.gz $BACKUP_DIR/ || exit $? +docker exec -ti $DOCKERID rm /tmp/db_lavaserver.gz || exit $? + +docker exec -ti $DOCKERID tar czf /root/joboutput.tar.gz /var/lib/lava-server/default/media/job-output/ || exit $? +docker cp $DOCKERID:/root/joboutput.tar.gz $BACKUP_DIR/ || exit $? +docker exec -ti $DOCKERID rm /root/joboutput.tar.gz || exit $? + +echo "Backup done in $BACKUP_DIR" diff --git a/lava-master/Dockerfile b/lava-master/Dockerfile index 7d61103..a074570 100644 --- a/lava-master/Dockerfile +++ b/lava-master/Dockerfile @@ -49,6 +49,8 @@ RUN /etc/init.d/postgresql start && \ bash /build-lava lava-server 2018.4 2018.4-1 && \ /etc/init.d/postgresql stop +COPY backup / + RUN a2enmod proxy \ && a2enmod proxy_http \ && a2dissite 000-default \ diff --git a/lava-master/backup/.empty b/lava-master/backup/.empty new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lava-master/backup/.empty diff --git a/lava-master/scripts/setup.sh b/lava-master/scripts/setup.sh index c00cb02..ad10238 100755 --- a/lava-master/scripts/setup.sh +++ b/lava-master/scripts/setup.sh @@ -7,6 +7,20 @@ fi sudo -u postgres psql -c "ALTER USER lavaserver WITH PASSWORD '$(cat /root/pg_lava_password)';" || exit $? sed -i "s,^LAVA_DB_PASSWORD=.*,LAVA_DB_PASSWORD='$(cat /root/pg_lava_password)'," /etc/lava-server/instance.conf || exit $? +if [ -e /db_lavaserver.gz ];then + gunzip /db_lavaserver.gz || exit $? +fi + +if [ -e /db_lavaserver ];then + echo "Restore database from backup" + sudo -u postgres psql < /db_lavaserver || exit $? + lava-server manage migrate || exit $? + echo "Restore jobs output from backup" + rm -r /var/lib/lava-server/default/media/job-output/* + tar xzf /joboutput.tar.gz || exit $? +fi +chown -R lavaserver:lavaserver /var/lib/lava-server/default/media/job-output/ + if [ -e /root/lava-users ];then for ut in $(ls /root/lava-users) do |