From 9f11d4eafe02cda95ec6e090f891b6326b6eb8ab Mon Sep 17 00:00:00 2001 From: Corentin LABBE Date: Wed, 8 Jan 2025 12:07:41 +0100 Subject: [PATCH] Let backup handle docker name different than master Signed-off-by: Corentin LABBE --- .github/workflows/basic.yml | 20 ++++++++++++++++++++ backup.sh | 31 ++++++++++++++++++++++++++++++- boards-ci2.yaml | 4 ++-- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index 176bab0..6664a0d 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -139,3 +139,23 @@ jobs: run: cd output/local && docker compose up -d - name: Wait for LAVA 2023.10 to be started run: sh .github/workflows/wait-for-docker.sh + test-backup: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: test valid and invalid usage of backup.sh + run: | + ./backup.sh -n && exit 1 + ./backup.sh -h || exit 1 + ./backup.sh --help || exit 1 + - run: ./lavalab-gen.py boards-ci2.yaml + - name: Build lava-docker + run: cd output/local && docker compose build + - name: Wait for LAVA to be started + run: sh .github/workflows/wait-for-docker.sh + - name: Run backup + run: ./backup.sh -n central + - name: Check backup + run: | + pwd + ls -l backup-latest diff --git a/backup.sh b/backup.sh index 2f5f748..685baa1 100755 --- a/backup.sh +++ b/backup.sh @@ -1,17 +1,46 @@ #!/bin/sh +DOCKERNAME=master BACKUP_DIR="backup-$(date +%Y%m%d_%H%M)" # use /tmp by default on host (this is used by tar) TMPDIR=${TMPDIR:-/tmp} export TMPDIR +usage() { + echo "$0 [-h|--help] [-n dockername]" +} + +while [ $# -ge 1 ] +do + case $1 in + -h) + usage + exit 0 + ;; + --help) + usage + exit 0 + ;; + -n) + shift + DOCKERNAME=$1 + shift + ;; + *) + usage + exit 1 + ;; + esac +done + mkdir -p $TMPDIR mkdir $BACKUP_DIR cp boards.yaml $BACKUP_DIR -DOCKERID=$(docker ps |grep master | cut -d' ' -f1) +DOCKERID=$(docker ps |grep "$DOCKERNAME" | cut -d' ' -f1) if [ -z "$DOCKERID" ];then + echo "ERROR: unable to find docker named $DOCKERNAME" exit 1 fi diff --git a/boards-ci2.yaml b/boards-ci2.yaml index bf4c8ae..16ddc27 100644 --- a/boards-ci2.yaml +++ b/boards-ci2.yaml @@ -1,6 +1,6 @@ --- masters: - - name: masterci1 + - name: central host: local users: - name: admin @@ -17,7 +17,7 @@ masters: slaves: - name: lab-ci-0 host: local - remote_master: masterci1 + remote_master: central remote_user: admin use_overlay_server: false use_tftp: false