From eeebc70d6f07921d3870b3ec9839db7d9315033f Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Wed, 10 Jul 2024 10:37:24 +0200 Subject: [PATCH] wip --- .github/workflows/sync_databases.yml | 31 ++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/sync_databases.yml b/.github/workflows/sync_databases.yml index c41dfa803..571b8ba46 100644 --- a/.github/workflows/sync_databases.yml +++ b/.github/workflows/sync_databases.yml @@ -26,13 +26,15 @@ jobs: run: | # Login to Scalingo, using the token stored in `DUPLICATE_API_TOKEN`: scalingo login --api-token "${DUPLICATE_API_TOKEN}" + - name: Install Scalingo CLI + run: | + scalingo --app "${{ secrets.DUPLICATE_SOURCE_APP }}" run install-scalingo-cli + - name: Install postgres tools + run: | + scalingo --app "${{ secrets.DUPLICATE_SOURCE_APP }}" run dbclient-fetcher "${DUPLICATE_ADDON_KIND}" - name: Generate database archive run: | archive_name="backup.tar.gz" - - # Install additional tools to interact with the database: - scalingo --app "${DUPLICATE_SOURCE_APP}" run dbclient-fetcher "${DUPLICATE_ADDON_KIND}" - # Retrieve the addon id: addon_id="$( scalingo --app "${DUPLICATE_SOURCE_APP}" addons \ | grep "${DUPLICATE_ADDON_KIND}" \ @@ -40,19 +42,22 @@ jobs: | tr -d " " )" # Download the latest backup available for the specified addon: - scalingo --app "${DUPLICATE_SOURCE_APP}" --addon "${addon_id}" \ - backups-download --output "${archive_name}" - + scalingo --app "${{ secrets.DUPLICATE_SOURCE_APP }}" run \ + scalingo --app "${DUPLICATE_SOURCE_APP}" --addon "${addon_id}" \ + backups-download --output "${archive_name}" - name: Restore the database run: | # Get the name of the backup file: - backup_file_name="$( tar --list --file="${archive_name}" \ - | tail -n 1 \ - | cut -d "/" -f 2 )" + scalingo --app "${{ secrets.DUPLICATE_SOURCE_APP }}" run \ + backup_file_name="$( tar --list --file="${archive_name}" \ + | tail -n 1 \ + | cut -d "/" -f 2 )" # Extract the archive containing the downloaded backup: - scalingo run --app "${DUPLICATE_SOURCE_APP}" tar --extract --verbose --file="${archive_name}" --directory="/app/" + scalingo --app "${{ secrets.DUPLICATE_SOURCE_APP }}" run \ + tar --extract --verbose --file="${archive_name}" --directory="/app/" # Restore the data: - scalingo run --app "${DUPLICATE_SOURCE_APP}" pg_restore --clean --if-exists --no-owner --no-privileges --no-comments \ - --dbname "${DATABASE_URL}" "/app/${backup_file_name}" + scalingo --app "${{ secrets.DUPLICATE_SOURCE_APP }}" run \ + pg_restore --clean --if-exists --no-owner --no-privileges --no-comments \ + --dbname "${DATABASE_URL}" "/app/${backup_file_name}"