Skip to content

Commit

Permalink
Merge pull request #1602 from danskernesdigitalebibliotek/lagoon-conf…
Browse files Browse the repository at this point in the history
…igurable-restore-env

Support restoring Lagoon backup from other environments than main
  • Loading branch information
kasperg authored Sep 30, 2024
2 parents 86f2fbb + f21bffc commit 2e73716
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ tasks:
desc: 'Restore database from db dump file. Only one sql should be present the "{{ .DIR_RESTORE_DATABASE }}" directory.'
cmds:
- task dev:cli -- drush sql:drop -y
- docker-compose exec -T {{ .MYSQL_CONTAINER }} mysql < {{ .SQL_FILE }}
- docker compose exec -T {{ .MYSQL_CONTAINER }} mysql < {{ .SQL_FILE }}
- task dev:cache:clear:all
preconditions:
- sh: "[ {{ .SQL_FILES_COUNT }} -gt 0 ]"
Expand All @@ -252,7 +252,7 @@ tasks:
dev:restore:files:
desc: "Restore files by overwriting existing with the ones from the Lagoon backup package"
cmds:
- docker-compose exec cli sh dev-scripts/cli-restore-lagoon-files.sh {{ .DIR_RESTORE_FILES }}
- docker compose exec cli sh dev-scripts/cli-restore-lagoon-files.sh {{ .DIR_RESTORE_FILES }}
- task dev:cache:clear:all

dev:cache:clear:all:
Expand Down
12 changes: 5 additions & 7 deletions dev-scripts/lagoon-get-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
# Restore and download files from a Lagoon backup.
set -eo pipefail

LAGOON_PROJECT="$1"
LAGOON_ENVIRONMENT="main"
BACKUP_TYPE="$2"
BACKUP_DESTINATION="$3"
LAGOON_ENVIRONMENT="${LAGOON_ENVIRONMENT:-main}"

if [[ -z "${LAGOON_PROJECT}" || -z "${BACKUP_TYPE}" || -z "${BACKUP_DESTINATION}" ]]; then
echo "usage: $0 <LAGOON_PROJECT> <BACKUP_TYPE> <BACKUP_DESTINATION>" >&2
echo "usage: LAGOON_PROJECT=<LAGOON_PROJECT> BACKUP_TYPE=<BACKUP_TYPE> BACKUP_DESTINATION=<BACKUP_DESTINATION> $0" >&2
exit 1
fi

BACKUPS=$(lagoon list backups -p "${LAGOON_PROJECT}" -e ${LAGOON_ENVIRONMENT} --output-json);
BACKUPS=$(lagoon list backups -p "${LAGOON_PROJECT}" -e "${LAGOON_ENVIRONMENT}" --output-json);
BACKUP_ID=$(echo "$BACKUPS" | jq -r ".data[] | select(.source == \"${BACKUP_TYPE}\") | .backupid" | head -n 1);
BACKUP_URL="Error";
echo -e "\nRetrieving ${BACKUP_TYPE} backup from ${LAGOON_ENVIRONMENT} environment of ${LAGOON_PROJECT} project \n\n";
# Wait a while we wait for the backup to become available.
# It must be retrieved before it can be downloaded.
while [[ $BACKUP_URL == "Error"* ]]; do
Expand All @@ -24,5 +22,5 @@ while [[ $BACKUP_URL == "Error"* ]]; do
# backup is not available for download yet.
BACKUP_URL=$(lagoon get backup -p "${LAGOON_PROJECT}" -e "${LAGOON_ENVIRONMENT}" --backup-id "${BACKUP_ID}" 2>/dev/null) || true;
done;
echo -e "\nDownloading backup from ${BACKUP_URL}\n\n";
echo -e "\nDownloading backup from ${BACKUP_URL} to ${BACKUP_DESTINATION}\n\n";
curl -o "${BACKUP_DESTINATION}" "${BACKUP_URL}";
14 changes: 8 additions & 6 deletions task/Taskfile.lagoon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@ tasks:
backup:restore:database:
desc: Restore the latest backup of the database from a Lagoon project
deps: [deps:lagoon, deps:jq, login]
vars:
LAGOON_ENVIRONMENT: main
cmds:
- ./dev-scripts/lagoon-get-backup.sh ${LAGOON_PROJECT} mariadb {{.DIR_RESTORE_DATABASE}}/${LAGOON_PROJECT}-backup.tar.gz;
- ./dev-scripts/lagoon-get-backup.sh
- cd ./restore/database/ && tar -xvzf ${LAGOON_PROJECT}-backup.tar.gz;
- task dev:restore:database
preconditions:
- sh: "[ -v LAGOON_PROJECT ]"
msg: Please provide a LAGOON_PROJECT environment variable with the name of the Lagoon project to use
env:
BACKUP_TYPE: "mariadb"
BACKUP_DESTINATION: "{{.DIR_RESTORE_DATABASE}}/{{.LAGOON_PROJECT}}-backup.tar.gz"

backup:restore:files:
desc: Restore the latest backup of the files from a Lagoon project
deps: [deps:lagoon, deps:jq, login]
vars:
LAGOON_ENVIRONMENT: main
cmds:
- ./dev-scripts/lagoon-get-backup.sh ${LAGOON_PROJECT} nginx {{.DIR_RESTORE_FILES}}/${LAGOON_PROJECT}-backup.tar.gz;
- ./dev-scripts/lagoon-get-backup.sh
- task dev:restore:files
preconditions:
- sh: "[ -v LAGOON_PROJECT ]"
msg: Please provide a LAGOON_PROJECT environment variable with the name of the Lagoon project to use
env:
BACKUP_TYPE: "nginx"
BACKUP_DESTINATION: "{{.DIR_RESTORE_FILES}}/{{.LAGOON_PROJECT}}-backup.tar.gz"

drush:uli:
desc: Get an Drupal one-time user login link for a Lagoon environment through Drush
Expand Down

0 comments on commit 2e73716

Please sign in to comment.