Post‑Restore Integrity Verification in Spatie Laravel Backup
0 reputation · 13 Apr 2022, 21:47 UTC
0 reputation · 13 Apr 2022, 21:47 UTC
The package’s php artisan backup:restore command restores the latest or a specified archive, writing data to the configured disk and database. It does not automatically verify that the restored files or database rows match the original backup.
When restoring a production snapshot, the absence of an integrity check means that corruption, partial writes, or accidental mis‑configuration could go unnoticed until a later failure. The design team is debating whether to embed a verification step, such as checksum comparison or a test suite run, and how to surface failures to the operator.
Unresolved questions include:
When you run php artisan backup:restore, the command simply unpacks the chosen archive to the configured disk and imports the database dump. It does not perform any checksum comparison or application‑level test after the restore completes. The package therefore offers no built‑in fallback policy for mismatches, nor a documented hook that runs automatically after the restore finishes.
RestoreCommand extracts the archive and runs the database import; no post‑restore verification logic is present.backup:restore via $this->call('backup:restore', …), then runs your own verification logic.
manifest.json (if you keep one) or compute hashes of key directories. For the database, run a set of sanity checks such as SELECT COUNT(*) FROM users and compare to a known baseline.
To tailor the recommendation precisely, could you let me know which major version of spatie/laravel-backup and which Laravel version you are using?
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 14 Apr 2022, 00:15 UTC
The manifest.json file that Spatie Laravel Backup includes in each archive lists each file’s relative path and size, but it does not store SHA‑1, MD5 or any other hash. Consequently, the restore command cannot compare a stored hash to the restored file without first generating one during the backup process.
Because the package does not dispatch any event after backup:restore finishes, the only reliable way to run application‑level tests or custom checks is to wrap the command in your own Artisan command (or a queued job) that calls $this->call('backup:restore', [...]) and then performs your verification logic.
If you need a built‑in fallback, you would have to modify the backup process to include a hash manifest (e.g., by adding a hashes.json to the zip) and then extend the restore command to compare those hashes after extraction.