Skip to content

Commit

Permalink
Fix migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolidori committed Oct 2, 2024
1 parent 5828459 commit 0d90ad0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions .docker-compose.vital-strategies-theme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
install_standard_ckan_extension_github -r ckan/ckanext-geoview && \
install_standard_ckan_extension_github -r datopian/ckanext-sentry -b 2.10 && \
install_standard_ckan_extension_github -r datopian/ckanext-gtm && \
install_standard_ckan_extension_github -r ckan/ckanext-googleanalytics -b 0055c3e06347c8ed31b7abe47aa06e3e44e0bf63 &&\
install_standard_ckan_extension_github -r datopian/ckanext-s3filestore -b ckan-2.10 && \
cd ~/venv/src/ckanext-querytool && ~/venv/bin/python setup.py compile_catalog -l en -f && \
cd ~/venv/src/ckanext-querytool && ~/venv/bin/python setup.py compile_catalog -l es -f && \
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ clean-rebuild:
docker-compose $(COMPOSE_FILES) up -d nginx && make cron

backup-db:
docker-compose $(COMPOSE_FILES) exec -T db pg_dump -U postgres --format=custom -d ckan > ckan.dump
docker-compose ${COMPOSE_FILES} exec -T ckan sh -c "cd /var/lib/ckan && tar -czf /tmp/ckan_data.tar.gz data"
docker cp $$(docker-compose ${COMPOSE_FILES} ps -q ckan):/tmp/ckan_data.tar.gz ckan_data.tar.gz
docker-compose $(COMPOSE_FILES) exec -T datastore-db pg_dump -U postgres --format=custom -d datastore > datastore.dump
docker-compose $(COMPOSE_FILES) exec -T db pg_dump -U postgres --format=custom -d ckan > ckan_test.dump
docker-compose ${COMPOSE_FILES} exec -T ckan sh -c "cd /var/lib/ckan && tar -czf /tmp/ckan_data_test.tar.gz data"
docker cp $$(docker-compose ${COMPOSE_FILES} ps -q ckan):/tmp/ckan_data_test.tar.gz ckan_data_test.tar.gz
docker-compose $(COMPOSE_FILES) exec -T datastore-db pg_dump -U postgres --format=custom -d datastore > datastore_test.dump

upgrade-db:
./db/migration/upgrade_databases.sh "$(COMPOSE_FILES)" "$(CKAN_DB_NAME)" "$(CKAN_DB_USERNAME)" "$(DB_USERNAME)" "$(DATASTORE_DB_NAME)" "$(DATASTORE_DB_USERNAME)"
Expand Down
10 changes: 6 additions & 4 deletions ckan/post_install_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ install_standard_ckan_extension_github() {
echo "#### BRANCH: $BRANCH ####"
echo "#### REPO URL: $GITHUB_URL/$REPO_NAME.git ####"

# Check if the branch exists by examining the output directly
BRANCH_EXISTS=$(git ls-remote --heads ${GITHUB_URL}/${REPO_NAME}.git ${BRANCH})

if [ ! -n "$BRANCH_EXISTS" ]; then
# It might be a commit instead of a branch
BRANCH_EXISTS=$(git ls-remote --heads ${GITHUB_URL}/${REPO_NAME}.git | grep -o $BRANCH)
if [ -z "$BRANCH_EXISTS" ]; then
BRANCH_EXISTS=$(git ls-remote --tags ${GITHUB_URL}/${REPO_NAME}.git ${BRANCH})

if [ -z "$BRANCH_EXISTS" ]; then
BRANCH_EXISTS=$(git ls-remote ${GITHUB_URL}/${REPO_NAME}.git | grep -o ${BRANCH})
fi
fi

if [ -z "$BRANCH_EXISTS" ]; then
Expand Down
16 changes: 10 additions & 6 deletions db/migration/upgrade_databases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ CKAN_SERVICE="ckan"
DB_SERVICE="db"
DATASTORE_SERVICE="datastore-db"
CKAN_CONFIG_PATH="/etc/ckan/ckan.ini"


DB_SERVICE_ID=$(docker-compose ${COMPOSE_FILES} ps -q ${DB_SERVICE})
DATASTORE_SERVICE_ID=$(docker-compose ${COMPOSE_FILES} ps -q ${DATASTORE_SERVICE})
CKAN_SERVICE_ID=$(docker-compose ${COMPOSE_FILES} ps -q ${CKAN_SERVICE})

if [ ! -f $CKAN_BACKUP_FILE ]; then
echo ""
Expand Down Expand Up @@ -60,7 +61,8 @@ echo ""
echo "### Restoring the CKAN DB from backup..."
echo ""

docker-compose ${COMPOSE_FILES} exec -T ${DB_SERVICE} pg_restore -U postgres --verbose --create --clean --if-exists -d postgres < ${CKAN_BACKUP_FILE}
docker cp ${CKAN_BACKUP_FILE} ${DB_SERVICE_ID}:/${CKAN_BACKUP_FILE}
docker-compose ${COMPOSE_FILES} exec -T ${DB_SERVICE} pg_restore -U postgres --verbose --create --clean --if-exists -d postgres /ckan.dump

echo ""
echo "### Restoring CKAN DB from backup completed."
Expand All @@ -69,7 +71,8 @@ echo ""
echo "### Restoring the Datastore DB from backup..."
echo ""

docker-compose ${COMPOSE_FILES} exec -T ${DATASTORE_SERVICE} pg_restore -U postgres --verbose --create --clean --if-exists -d postgres < ${DATASTORE_BACKUP_FILE}
docker cp ${DATASTORE_BACKUP_FILE} ${DATASTORE_SERVICE_ID}:/${DATASTORE_BACKUP_FILE}
docker-compose ${COMPOSE_FILES} exec -T ${DATASTORE_SERVICE} pg_restore -U postgres --verbose --create --clean --if-exists -d postgres /datastore.dump

echo ""
echo "### Restoring Datastore DB from backup completed."
Expand All @@ -85,8 +88,9 @@ echo ""
echo "### Restoring data files to CKAN..."
echo ""

docker cp ${CKAN_DATA_BACKUP_FILE} $(docker-compose ${COMPOSE_FILES} ps -q ckan):/tmp/ckan_data.tar.gz
docker-compose ${COMPOSE_FILES} exec -T ${CKAN_SERVICE} bash -c "tar -xzf /tmp/ckan_data.tar.gz -C /tmp/ && cp -r /tmp/data/* /var/lib/ckan/data/ && chown -R ckan:ckan /var/lib/ckan/data"
docker cp ${CKAN_DATA_BACKUP_FILE} ${CKAN_SERVICE_ID}:/${CKAN_DATA_BACKUP_FILE}

docker-compose ${COMPOSE_FILES} exec -T ${CKAN_SERVICE} bash -c "tar -xzf /ckan_data.tar.gz -C /data && cp -r /data/* /var/lib/ckan/data/ && chown -R ckan:ckan /var/lib/ckan/data"

echo ""
echo "### Data files restored to CKAN."
Expand Down

0 comments on commit 0d90ad0

Please sign in to comment.