Skip to main content

Backup Logging and Verification

Backups fail in predictable ways: the job runs but produces an empty dump, the remote upload fails, or the archive is corrupt. Logging and verification make these failures visible immediately.

Quick Summary
  • Log every run (timestamp, host, exit code, artifact sizes).
  • Verify integrity (gzip -t, zstd -t, xz -t).
  • Verify contents (list archive, find key WordPress paths).
  • Run restore drills into staging directories.

What to log

At minimum:

  • When the job started/ended.
  • What artifacts were created.
  • Artifact sizes.
  • Exit codes.
  • Remote upload status.

A simple log wrapper

backup-log-wrapper.sh
#!/usr/bin/env bash
set -euo pipefail

LOG_DIR="/backups/logs"
mkdir -p "$LOG_DIR"

STAMP="$(date +%F)"
LOG="$LOG_DIR/backup-$STAMP.log"

{
echo "[$(date -Is)] start"
echo "host=$(hostname)"

/usr/local/bin/wp-backup-full

echo "[$(date -Is)] done"
} | tee -a "$LOG"

Integrity verification

Examples:

verify-gzip-artifact.sh
gzip -t /backups/wp-db-2026-03-01.sql.gz
verify-zstd-artifact.sh
zstd -t /backups/wp-files-2026-03-01.tar.zst

Content verification (files)

List archive contents and check for expected paths.

verify-files-archive-contents.sh
tar --use-compress-program=zstd -tf /backups/wp-files-2026-03-01.tar.zst | sed -n '1,40p'
tar --use-compress-program=zstd -tf /backups/wp-files-2026-03-01.tar.zst | rg -n 'wp-content|wp-config\.php' | sed -n '1,20p'

Restore drill (staging)

warning

Do not restore into /var/www/html until you have validated the archive in a staging directory.

restore-drill-files-archive.sh
sudo rm -rf /tmp/restore-test
sudo mkdir -p /tmp/restore-test

sudo tar --use-compress-program=zstd -xf /backups/wp-files-2026-03-01.tar.zst -C /tmp/restore-test
sudo find /tmp/restore-test -maxdepth 3 -type f -name wp-config.php -print

Database restore drills should be done into a staging database:

restore-drill-db-dump.sh
zstd -dc /backups/wp-db-2026-03-01.sql.zst | mysql wordpress_restore

Next steps

  • Email logs: opt/docker-data/apps/docusaurus/site/docs/server/linux-server/10-backup-disaster-recovery/email-backup-logs.mdx.
  • Alerting: opt/docker-data/apps/docusaurus/site/docs/server/linux-server/10-backup-disaster-recovery/alert-on-failed-backup-jobs.mdx.