Skip to content

Commit

Permalink
remove create and use instruction #1152
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinx13 committed Dec 21, 2023
1 parent de4d25f commit 4981ca3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion scripts/sync-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,39 @@
archive_name="backup.tar.gz"

# Install the Scalingo CLI tool in the container:
echo "Install the Scalingo CLI tool in the container"
install-scalingo-cli

# Install additional tools to interact with the database:
echo "Install additional tools to interact with the database"
dbclient-fetcher mysql 5.7

# Login to Scalingo, using the token stored in `DUPLICATE_API_TOKEN`:
echo "Login to Scalingo"
scalingo login --api-token "${DUPLICATE_API_TOKEN}"

# Retrieve the addon id:
echo "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:
echo "Download the latest backup available for the specified addon"
scalingo --app "${DUPLICATE_SOURCE_APP}" --addon "${addon_id}" \
backups-download --output "${archive_name}"

# Extract the archive containing the downloaded backup:
echo "Extraction the archive containing the downloaded backup"
backup_file_name="$( tar --extract --verbose --file="${archive_name}" --directory="/app/" \
| cut -d " " -f 2 | cut -d "/" -f 2 )"

mysql -u ${DATABASE_USER} --password=${DATABASE_PASSWORD} -h ${DATABASE_HOST} -P ${DATABASE_PORT} ${DATABASE_NAME} < "/app/${backup_file_name}"
# Remove CREATE and USE instruction
echo "Remove CREATE and USE instruction"
sed -i '/CREATE DATABASE/d' "app/${backup_file_name}"
sed -i '/^USE/d' "app/${backup_file_name}"

# Load database
echo "Load database"
mysql -u ${DATABASE_USER} --password=${DATABASE_PASSWORD} -h ${DATABASE_HOST} -P ${DATABASE_PORT} ${DATABASE_NAME} < "app/${backup_file_name}"

0 comments on commit 4981ca3

Please sign in to comment.