Skip to content

How to detect a WordPress backup that fails silently

Detect a WordPress backup that reports success but cannot be used, with five checks that run every night on the backup files themselves. You will test the dump, the archive, its size and its file count, and get an email the night one of them fails.

Your backup plugin, cPanel or cron job says last night’s WordPress backup succeeded, and you want proof that the files it wrote are usable. A “success” status only records that the backup program exited without complaining. It says nothing about whether the database dump is complete, whether every upload made it into the archive, or whether the copy landed where you would restore from. The fix is to check the backup files themselves every night. A short script reads the dump’s last line, tests the archives, compares sizes and file counts, and emails you when any check fails. You end up with an alert the morning after a backup breaks, instead of a surprise on the day you need it.

What you’ll accomplish

  • Know exactly where your newest backup lands and how old it is, on local disk and off-site.
  • Prove that a database dump ran to the end by reading the trailer line mysqldump writes last.
  • Test every compressed archive for truncation with gzip -t and tar -tzf.
  • Catch shrinking backups and missing uploads by comparing sizes and file counts between runs.
  • Run all of it from cron each morning, with an email the first time something fails.

Prerequisites

  • SSH access to the server where the backup files land, or to a machine that receives a copy. The commands assume Linux with GNU tar, gzip and find.
  • Backups written as a gzipped mysqldump file (.sql.gz) plus a tar.gz of the site files. UpdraftPlus works differently: it zips the site files (tested with unzip -tq in step 4) and writes the database with its own exporter, so its -db.gz file never carries the mysqldump trailer from step 3. The gzip -t test still applies to it.
  • mysqldump from MySQL 8 or MariaDB 10.5 or later. On recent MariaDB the same program is also called mariadb-dump, and its output format is the same.
  • A working mail command (from the mailutils or s-nail package) for alerts. A webhook with curl works as well.
  • Optional: WP-CLI, so you can ask WordPress to check its own database tables from SSH (used in Troubleshooting).

Throughout, example is the site’s system user, /home/example/public_html is the WordPress root and /backup/example-site is the backup folder. Replace them with your own paths.

How it works

A WordPress backup is a pipeline: read the files, dump the database, compress and write the result, then copy it somewhere safe. Each stage can break while the job as a whole still reports success.

Four backup stages, each with the silent failure it can hide and the command that exposes it, all feeding one nightly check that emails on failure

The four failure classes, and the signal that catches each one:

  1. Files the backup user cannot read. A plugin or an admin running as root creates files the backup process has no permission to open. GNU tar prints Cannot open: Permission denied and exits with status 2. Some PHP backup plugins log a warning, skip the file and carry on. The signal is a count: uploads on disk versus uploads in the archive.
  2. A database dump that stops partway. mysqldump writes -- Dump completed on <date> as its very last line. If a lock timeout, a crashed table or a lost connection stops it early, that line is missing. The classic trap is the pipe mysqldump | gzip > file. Without set -o pipefail, the shell option that makes a pipe fail when any command in it fails, the shell reports only the exit status of gzip, which is 0. You get a small or empty gzip file that passes gzip -t, and a green status.
  3. An archive cut short at the destination. A full disk, a dropped transfer or a killed process leaves a truncated .gz file. gzip -t and tar -tzf both fail on it, and its size drops sharply compared with the night before.
  4. Backups landing somewhere nobody restores from. Rotated cloud credentials, a renamed bucket or a changed path leave the job writing to the wrong place, or nowhere at all. The signal is the age of the newest file in the location you would actually restore from.

None of these checks needs a restore, so they are cheap enough to run every night. A quarterly restore drill proves a backup works on the day of the drill. These checks tell you the morning after a backup breaks. For the drill itself, see verifying that a WordPress backup is restorable.

Step-by-step

  1. Find the newest backup and its age. List the backup folder, newest first.

    ls -lt --time-style=long-iso /backup/example-site | head -n 5

    Example output:

    total 12974316
    -rw-r----- 1 example example 912384117 2026-10-18 03:17 files-20261018-0300.tar.gz
    -rw-r----- 1 example example  38114926 2026-10-18 03:04 db-20261018-0300.sql.gz
    -rw-r----- 1 example example 909770213 2026-10-17 03:16 files-20261017-0300.tar.gz
    -rw-r----- 1 example example  38090452 2026-10-17 03:05 db-20261017-0300.sql.gz

    You want a file from last night’s run at the top. If the newest file is two or more days old, the job is failing before it writes anything, or it is writing somewhere else. If you copy backups off-site to Amazon S3, check that location too, because that is the copy you would restore from after losing the server:

    aws s3 ls s3://example-backups/example-site/ | sort | tail -n 2

    Each line starts with the upload date and time, so sort puts the newest objects last. Example output:

    2026-10-18 03:41:52   38114926 db-20261018-0300.sql.gz
    2026-10-18 03:49:07  912384117 files-20261018-0300.tar.gz

    If the keys used by the job were rotated, this command run with the same credentials fails with An error occurred (InvalidAccessKeyId) when calling the ListObjectsV2 operation. That is the credentials drift from failure class 4.

  2. Confirm the destination has room. A disk that fills during the night produces partial files.

    df -h /backup

    Example output:

    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sdb1       492G  431G   37G  93% /backup

    Keep at least two full backups’ worth of free space. Here one night needs about 1 GB, so 37 GB is fine. A run that hit a full disk leaves gzip: stdout: No space left on device in the job’s output or cron email.

  3. Prove the dump ran to the end. Read the last line of the newest dump.

    zcat /backup/example-site/db-20261018-0300.sql.gz | tail -n 1

    Example output:

    -- Dump completed on 2026-10-18  3:04:11

    That line means mysqldump reached the end of every table. The hour is padded with a space, so a single-digit hour shows two spaces after the date. Anything else on the last line, such as half an INSERT statement, means the dump stopped early. Two exceptions: dumps made with --skip-comments or --compact never write the trailer, and --skip-dump-date writes -- Dump completed with no date. If your command uses either of the first two flags, remove them.

    If the trailer is missing, fix the dump command so a failure can no longer hide behind the pipe. Put the database credentials in ~/.my.cnf for the backup user, then:

    set -o pipefail
    mysqldump --single-transaction --quick --no-tablespaces example_wp \
      | gzip > /backup/example-site/db-$(date +%Y%m%d-%H%M).sql.gz
    echo "exit=$?"

    Example output on a healthy run:

    exit=0

    Example output when the password is wrong (MariaDB):

    mysqldump: Got error: 1045: "Access denied for user 'example'@'localhost' (using password: YES)" when trying to connect
    exit=2

    Without set -o pipefail, that same failure prints exit=0 and leaves a 20-byte file behind. --single-transaction takes a consistent snapshot of InnoDB tables (the default MySQL table type) without locking the site. --quick streams rows instead of holding whole tables in memory. --no-tablespaces skips tablespace metadata, which MySQL 8 only lets users with the PROCESS privilege read, and most site database users do not have it.

  4. Test the archives for truncation. gzip -t prints nothing and exits 0 when a file is intact.

    gzip -t /backup/example-site/db-20261018-0300.sql.gz; echo "gzip=$?"
    tar -tzf /backup/example-site/files-20261018-0300.tar.gz > /dev/null; echo "tar=$?"

    Example output for intact files:

    gzip=0
    tar=0

    Example output when both files were cut short:

    gzip: /backup/example-site/db-20261018-0300.sql.gz: unexpected end of file
    gzip=1
    gzip: stdin: unexpected end of file
    tar: Unexpected EOF in archive
    tar: Error is not recoverable: exiting now
    tar=2

    For UpdraftPlus zip archives, use unzip -tq on each file. An intact archive prints one line, No errors detected in compressed data of followed by the file name and a period. Any other output, or a non-zero exit status, means the zip is damaged.

  5. Compare sizes with the previous run. A WordPress database and its uploads grow slowly, so a sudden drop is a warning sign.

    stat -c '%s %n' /backup/example-site/db-2026101[78]-0300.sql.gz

    Example output:

    38090452 /backup/example-site/db-20261017-0300.sql.gz
    38114926 /backup/example-site/db-20261018-0300.sql.gz

    Use this rule: if the newest file is less than 80% of the size of the previous one, investigate before the next run. A legitimate cleanup, such as purging old revisions or spam comments, can trigger it once. Read the job output, confirm the cleanup was intended, and the next night’s comparison resets.

  6. Count uploads on disk against uploads in the archive. First, list files the backup user cannot read. Run this as the user the backup runs as, not as root.

    sudo -u example find /home/example/public_html/wp-content -type f ! -readable

    No output means every file is readable. Example output when a file was created by root with tight permissions:

    /home/example/public_html/wp-content/uploads/2026/10/invoice-template.pdf

    Then compare counts. ! -newer limits the live count to files that already existed when the archive was written.

    find /home/example/public_html/wp-content/uploads -type f \
      ! -newer /backup/example-site/files-20261018-0300.tar.gz | wc -l
    tar -tzf /backup/example-site/files-20261018-0300.tar.gz \
      | grep -c 'wp-content/uploads/.*[^/]$'

    Example output:

    18342
    18341

    The two numbers should match. A lower archive count means files were skipped. Fix ownership with chown -R example:example /home/example/public_html/wp-content/uploads, then confirm the next archive matches.

  7. Read the backup tool’s own log. The archive checks catch damage. The log tells you why it happened. UpdraftPlus keeps one log per run as wp-content/updraft/log.<id>.txt:

    grep -iE 'warning|error' $(ls -t /home/example/public_html/wp-content/updraft/log.*.txt | head -n 1)

    No output means the run logged no warnings. For cPanel’s own backup system, the run logs live in /usr/local/cpanel/logs/cpbackup/. For JetBackup 5, open WHM, go to JetBackup 5, then Logs, and open any backup run whose status is not Completed.

  8. Install the nightly check. Save this as /usr/local/bin/check-wp-backup.sh and edit the five settings at the top. File names must follow the db-*.sql.gz and files-*.tar.gz pattern, or adjust the globs.

    #!/usr/bin/env bash
    # check-wp-backup.sh - alert when last night's WordPress backup is not usable
    set -uo pipefail
    
    BACKUP_DIR="/backup/example-site"          # where the backups land
    SITE_DIR="/home/example/public_html"       # the live WordPress root
    ALERT_TO="ops@example.com"
    MAX_AGE_MIN=1560                           # 26 hours
    MIN_PCT=80                                 # newest must be >= 80% of previous
    
    problems=()
    
    sql=$(ls -1t "$BACKUP_DIR"/db-*.sql.gz 2>/dev/null | head -n 1)
    prev_sql=$(ls -1t "$BACKUP_DIR"/db-*.sql.gz 2>/dev/null | sed -n 2p)
    files=$(ls -1t "$BACKUP_DIR"/files-*.tar.gz 2>/dev/null | head -n 1)
    
    if [ -z "$sql" ] || [ -z "$files" ]; then
      problems+=("no backup files found in $BACKUP_DIR")
    else
      # 1. Freshness: did tonight's run land here at all?
      [ -n "$(find "$sql" -mmin -"$MAX_AGE_MIN")" ] || problems+=("newest dump is older than $MAX_AGE_MIN minutes: $sql")
    
      # 2. Integrity of the compressed files
      gzip -t "$sql" 2>/dev/null || problems+=("gzip -t failed: $sql")
      tar -tzf "$files" >/dev/null 2>&1 || problems+=("tar -tzf failed: $files")
    
      # 3. Completeness of the dump: the last line must be the trailer
      zcat "$sql" 2>/dev/null | tail -n 1 | grep -q '^-- Dump completed' \
        || problems+=("dump has no 'Dump completed' trailer: $sql")
    
      # 4. Size delta against the previous dump
      if [ -n "$prev_sql" ]; then
        new_size=$(stat -c %s "$sql"); old_size=$(stat -c %s "$prev_sql")
        if [ $(( new_size * 100 )) -lt $(( old_size * MIN_PCT )) ]; then
          problems+=("dump shrank: $old_size -> $new_size bytes")
        fi
      fi
    
      # 5. Uploads that existed when the archive was written must be in it
      live=$(find "$SITE_DIR/wp-content/uploads" -type f ! -newer "$files" | wc -l)
      archived=$(tar -tzf "$files" 2>/dev/null | grep -c 'wp-content/uploads/.*[^/]$')
      if [ "$archived" -lt "$live" ]; then
        problems+=("uploads: $live files on disk, $archived in archive")
      fi
    fi
    
    if [ "${#problems[@]}" -gt 0 ]; then
      printf '%s\n' "${problems[@]}" | mail -s "Backup check FAILED on $(hostname)" "$ALERT_TO"
      printf '%s\n' "${problems[@]}" >&2
      exit 1
    fi
    echo "backup check OK: $(basename "$sql"), $(basename "$files")"

    Make it executable and schedule it a few hours after the backup window. With backups at 03:00, 06:30 leaves room for a slow night:

    chmod 755 /usr/local/bin/check-wp-backup.sh
    ( crontab -l 2>/dev/null; echo '30 6 * * * /usr/local/bin/check-wp-backup.sh' ) | crontab -
    crontab -l | grep check-wp-backup

    Example output:

    30 6 * * * /usr/local/bin/check-wp-backup.sh

    Install the crontab for a user that can read both the backup folder and the site, such as the site user. If your off-site copy is the one you would restore from, run a second freshness check against it. For example, compare the date on the last line of the sorted aws s3 ls listing from step 1 with today’s date.

Validate it works

Run the script by hand against last night’s backup:

/usr/local/bin/check-wp-backup.sh; echo "exit=$?"

Example output:

backup check OK: db-20261018-0300.sql.gz, files-20261018-0300.tar.gz
exit=0

Now prove it actually alerts. Create a deliberately broken dump that is newer than the real one, run the check, then delete the fake file:

head -c 4000 /backup/example-site/db-20261018-0300.sql.gz > /backup/example-site/db-29990101-0000.sql.gz
/usr/local/bin/check-wp-backup.sh; echo "exit=$?"
rm /backup/example-site/db-29990101-0000.sql.gz

Example output:

gzip -t failed: /backup/example-site/db-29990101-0000.sql.gz
dump has no 'Dump completed' trailer: /backup/example-site/db-29990101-0000.sql.gz
dump shrank: 38114926 -> 4000 bytes
exit=1

Within a few minutes the same three lines should arrive by email at ALERT_TO. If the terminal shows the failures but no email arrives, the alert path is broken, and that matters as much as the check. Run the script once more after deleting the fake file and confirm it reports OK.

Troubleshooting

  • The trailer is missing but gzip -t passes. The dump stopped cleanly partway, usually on a damaged table, a lock wait or an oversized row. Check the live tables with wp db check --path=/home/example/public_html, which runs mysqlcheck (or mariadb-check). It prints each table name followed by its status, then Success: Database checked. Repair any table whose status is not OK, then rerun the dump by hand and read its error output.
  • mail: command not found. Install mailutils on Debian or Ubuntu, or s-nail on AlmaLinux and Rocky Linux. If the server cannot send email, replace the mail line with a curl call to your chat or paging webhook.
  • The upload count is short every night. Run the ! -readable check from step 6 as the backup user. If nothing is unreadable, check the backup tool’s exclusion list. Some setups deliberately skip folders like wp-content/uploads/cache, in which case add the same exclusion to the find in the script.
  • Shrink alerts after every cleanup. Expected the first night after a large purge. If alerts repeat with no cleanup, compare the table list in the two dumps with zcat <file> | grep -c '^CREATE TABLE'. A missing table usually means the dump user lost a privilege.
  • The freshness check fails although the job reports success. The job is writing somewhere else. Read the destination path and credentials in the job settings, and compare them with the folder or bucket the check reads.

When this is the wrong approach

These checks prove a backup is complete and intact. They do not prove it restores into a working site, since plugins, URLs and server versions can still trip a restore. Pair them with a quarterly restore drill and an off-site copy, as set out in the 3-2-1 backup strategy for WordPress.

If you back up with whole-server snapshots or physical database copies (mariabackup, Percona XtraBackup), there is no SQL dump to inspect. Use those tools’ own verification, such as preparing the copy, instead of the trailer check. On managed WordPress hosting without SSH, you cannot run cron scripts on the server. Download a backup monthly and run steps 3 to 5 on your own machine. For the full option list, see the mysqldump reference and the wp db check documentation.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.