Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienheureux committed Jul 10, 2024
1 parent 6cf3d1c commit bf12f3b
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions .github/workflows/sync_databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
DUPLICATE_SOURCE_APP: ${{ secrets.DUPLICATE_SOURCE_APP }}
DUPLICATE_ADDON_KIND: postgresql
PREPROD_DATABASE_URL: ${{ secrets.PREPROD_DATABASE_URL }}
ARCHIVE_NAME: "backup.tar.gz"

defaults:
run:
Expand All @@ -21,38 +22,44 @@ jobs:
- name: Install Scalingo CLI
run: |
curl -O https://cli-dl.scalingo.com/install && bash install
- name: Login to Scalingo
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}" \
| cut -d "|" -f 3 \
| tr -d " " )"
scalingo --app "${{ secrets.DUPLICATE_SOURCE_APP }}" run \
addon_id="$( scalingo --app "${DUPLICATE_SOURCE_APP}" addons \
| grep "${DUPLICATE_ADDON_KIND}" \
| cut -d "|" -f 3 \
| 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}"

0 comments on commit bf12f3b

Please sign in to comment.