For the rare cases we want to sync production from the development site
We already have a monthly sync that completely overrides stage and dev environments directly from production. We don't have any automation in place for the reverse process, as it can be risky but also rarely needed.
As part of the new Information Architecture project it's often easier for NROs to content freeze on production, make all the necessary changes on their dev site and then ask from the P4 team to migrate them over to production.
Till we have an automated way of doing this type of sync, below are the manual steps needed to make it work.
Preperation
Maintenance page
Install the Maintenance plugin and configure it like documented here on both development and production sites and enable maintenance mode.
Set up env variables
Replace NRO with the name of the website (eg. indonesia) you are working on:
echo "Switch to prod cluster"
gcloud container clusters get-credentials "${GCLOUD_CLUSTER_PROD}" --zone "${GCLOUD_ZONE}" --project "${GOOGLE_PROJECT_ID_PROD}"
kc="kubectl -n ${HELM_NAMESPACE_PROD}"
echo "Find running php pod"
POD=$($kc get pods -l component=php | tail -1 | cut -d' ' -f1)
echo "Export prod database as a backup"
DB=$($kc exec "${POD}" -- wp db export | cut -d' ' -f4 | sed -e "s/'\.//" -e "s/'//")
$kc cp "${POD}":"${DB}" data-prod.sql
echo "Fetch prod bucket as a backup"
mkdir ${BUCKET_PROD}
gcloud storage rsync gs://${BUCKET_PROD} ${BUCKET_PROD}/ --recursive
Database import
First we need to open the database sql file on an editor and remove the lines that set up LOG BIN. Those are usually on the very first and on the very last lines of the file. Those command will make the import fail due to privillege issues.