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 eeebc70
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions .github/workflows/sync_databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,38 @@ 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}" \
| 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 eeebc70

Please sign in to comment.