drupalwxt / helm-drupal

Helm Chart for deploying an enterprise-grade Drupal environment.
https://drupalwxt.github.io/helm-drupal/index.yaml
MIT License
31 stars 22 forks source link

Backup cronjob fail due to tar file reporting file changes during backup #134

Open bernardmaltais opened 2 years ago

bernardmaltais commented 2 years ago

I ran into a similar issue as what @Stemirabo reported during restore and fixed via a patch.

I have fixed my issue with a patch for the cronjob script... but ultimately, I think the whole script should be made customizable via the values files. This will require quite a bit of work and would be a breaking change... so, I did not bother creating a pull request for it.

I think discussing long term possibilities for making script more customizable is required to better plan how it should be implemented.

Here is a copy of the patch I created to fix the problem:

spec:
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: drush
              command:
                - /bin/sh
                - '-c'
                - |
                  # Errors should fail the job
                  set -e
                  set +x

                  # Wait for DB to be available
                  until drush sql:query 'SHOW GLOBAL STATUS LIKE "Uptime";'; do echo Waiting for DB; sleep 3; done;
                  echo DB available;

                  # Check Drush status
                  drush status

                  # Run cron
                  BACKUPNAME=$(date +%Y%m%d.%H%M%S)
                  mkdir -p /backup/$BACKUPNAME
                  echo "Backup folder name: $BACKUPNAME"

                  echo "Backup DB"
                  drush -y sql-dump --skip-tables-list=cache,cache_* | gzip > /backup/$BACKUPNAME/db.sql.gz
                  echo "...backup DB completed."

                  echo "Backup public files"
                  set +e
                  tar --exclude="./js" --exclude="./css" --exclude="./styles" -czf /backup/$BACKUPNAME/files.tar.gz --directory=sites/default/files .
                  echo "...backup public files completed."
                  exitcode=$?
                  if [ "$exitcode" != "1" ] && [ "$exitcode" != "0" ];
                  then
                    exit $exitcode
                  fi
                  set -e

                  echo "Backup private files"
                  tar --exclude="./config" -czf /backup/$BACKUPNAME/private.tar.gz --directory=/private .

                  echo "...backup private files completed."

I guess we could run into the same issue with the private files backup... so, I might have to add the fix there to also...

I also added a bunch of echo to better see when things are completed and changed how I detect when the DB is ready. Therefore full script customization would be good as each teams using the chart might need slightly different backup and restore scripts.