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
mysqldumpwrites last. - Test every compressed archive for truncation with
gzip -tandtar -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,gzipandfind. - Backups written as a gzipped
mysqldumpfile (.sql.gz) plus atar.gzof the site files. UpdraftPlus works differently: it zips the site files (tested withunzip -tqin step 4) and writes the database with its own exporter, so its-db.gzfile never carries themysqldumptrailer from step 3. Thegzip -ttest still applies to it. mysqldumpfrom MySQL 8 or MariaDB 10.5 or later. On recent MariaDB the same program is also calledmariadb-dump, and its output format is the same.- A working
mailcommand (from themailutilsors-nailpackage) for alerts. A webhook withcurlworks 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.
The four failure classes, and the signal that catches each one:
- 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
tarprintsCannot open: Permission deniedand 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. - A database dump that stops partway.
mysqldumpwrites-- 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 pipemysqldump | gzip > file. Withoutset -o pipefail, the shell option that makes a pipe fail when any command in it fails, the shell reports only the exit status ofgzip, which is 0. You get a small or empty gzip file that passesgzip -t, and a green status. - An archive cut short at the destination. A full disk, a dropped transfer or a killed process leaves a truncated
.gzfile.gzip -tandtar -tzfboth fail on it, and its size drops sharply compared with the night before. - 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
-
Find the newest backup and its age. List the backup folder, newest first.
ls -lt --time-style=long-iso /backup/example-site | head -n 5Example 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.gzYou 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 2Each line starts with the upload date and time, so
sortputs 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.gzIf 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. -
Confirm the destination has room. A disk that fills during the night produces partial files.
df -h /backupExample output:
Filesystem Size Used Avail Use% Mounted on /dev/sdb1 492G 431G 37G 93% /backupKeep 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 devicein the job’s output or cron email. -
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 1Example output:
-- Dump completed on 2026-10-18 3:04:11That line means
mysqldumpreached 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 anINSERTstatement, means the dump stopped early. Two exceptions: dumps made with--skip-commentsor--compactnever write the trailer, and--skip-dump-datewrites-- Dump completedwith 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.cnffor 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=0Example 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=2Without
set -o pipefail, that same failure printsexit=0and leaves a 20-byte file behind.--single-transactiontakes a consistent snapshot of InnoDB tables (the default MySQL table type) without locking the site.--quickstreams rows instead of holding whole tables in memory.--no-tablespacesskips tablespace metadata, which MySQL 8 only lets users with thePROCESSprivilege read, and most site database users do not have it. -
Test the archives for truncation.
gzip -tprints 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=0Example 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=2For UpdraftPlus zip archives, use
unzip -tqon each file. An intact archive prints one line,No errors detected in compressed data offollowed by the file name and a period. Any other output, or a non-zero exit status, means the zip is damaged. -
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.gzExample output:
38090452 /backup/example-site/db-20261017-0300.sql.gz 38114926 /backup/example-site/db-20261018-0300.sql.gzUse 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.
-
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 ! -readableNo 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.pdfThen compare counts.
! -newerlimits 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 18341The 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. -
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. -
Install the nightly check. Save this as
/usr/local/bin/check-wp-backup.shand edit the five settings at the top. File names must follow thedb-*.sql.gzandfiles-*.tar.gzpattern, 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-backupExample output:
30 6 * * * /usr/local/bin/check-wp-backup.shInstall 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 lslisting 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 -tpasses. The dump stopped cleanly partway, usually on a damaged table, a lock wait or an oversized row. Check the live tables withwp db check --path=/home/example/public_html, which runsmysqlcheck(ormariadb-check). It prints each table name followed by its status, thenSuccess: Database checked.Repair any table whose status is notOK, then rerun the dump by hand and read its error output. mail: command not found. Installmailutilson Debian or Ubuntu, ors-nailon AlmaLinux and Rocky Linux. If the server cannot send email, replace themailline with acurlcall to your chat or paging webhook.- The upload count is short every night. Run the
! -readablecheck from step 6 as the backup user. If nothing is unreadable, check the backup tool’s exclusion list. Some setups deliberately skip folders likewp-content/uploads/cache, in which case add the same exclusion to thefindin 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.