Why Test Restores?
A backup that cannot be restored is worthless. According to industry surveys, up to 30% of backup restores fail due to corrupted files, missing data, or untested procedures. Regular testing is essential.
Database Restore Test
# Create a test database
mysql -u root -e "CREATE DATABASE restore_test;"
# Restore from backup
gunzip < /backups/mysql/mydb_latest.sql.gz | mysql -u root restore_test
# Verify data
mysql -u root restore_test -e "SELECT COUNT(*) FROM users;"
mysql -u root restore_test -e "SHOW TABLES;"
# Clean up
mysql -u root -e "DROP DATABASE restore_test;"File Restore Test
# Create restore directory
mkdir /tmp/restore-test
# Restore from tar backup
tar xzf /backups/www-latest.tar.gz -C /tmp/restore-test
# Compare with original
diff -rq /var/www/html /tmp/restore-test/var/www/html
# Clean up
rm -rf /tmp/restore-testFull Server Restore Test
- Deploy a temporary Breeze (test environment)
- Restore all backups (files, database, configuration)
- Verify the application works end-to-end
- Check all critical features
- Destroy the test server
Automated Verification Script
#!/bin/bash
BACKUP_FILE="/backups/mysql/mydb_latest.sql.gz"
TEST_DB="restore_verify_$(date +%s)"
# Test that backup file exists and is not empty
if [ ! -s "$BACKUP_FILE" ]; then
echo "FAIL: Backup file missing or empty" | mail -s "Backup Verify Failed" admin@example.com
exit 1
fi
# Test restore
mysql -u root -e "CREATE DATABASE $TEST_DB;"
gunzip < "$BACKUP_FILE" | mysql -u root "$TEST_DB" 2>/tmp/restore_error.log
if [ $? -ne 0 ]; then
echo "FAIL: Restore failed" | mail -s "Backup Verify Failed" admin@example.com
mysql -u root -e "DROP DATABASE IF EXISTS $TEST_DB;"
exit 1
fi
# Verify table count
TABLES=$(mysql -u root "$TEST_DB" -e "SHOW TABLES;" | wc -l)
if [ "$TABLES" -lt 2 ]; then
echo "FAIL: Only $TABLES tables found" | mail -s "Backup Verify Failed" admin@example.com
fi
mysql -u root -e "DROP DATABASE $TEST_DB;"
echo "Backup verification passed: $TABLES tables restored successfully"Schedule Monthly Tests
0 4 1 * * /usr/local/bin/verify-backup.sh >> /var/log/backup-verify.log 2>&1