• Reading time ~ 1 min
  • 22.06.2023

The Laravel Backup Restore is a package to restore database backups made with Spatie's laravel-backup package:

Adding the finishing touches on laravel-backup-restore.
Currently writing a blog post explaining everything.
v1 should be tagged by mid June.https://t.co/uRubDv4CDw

— Stefan Zweifel (@_stefanzweifel) May 31, 2023

This package provides an Artisan command to restore a backup as well as some customizable health checks and backup integrity checks. Here's an example of the artisan command from the project's README:

php artisan backup:restore
    --disk=s3
    --backup=latest
    --connection=mysql
    --password=my-secret-password
    --reset

After the backup is restored, this package will run some health checks to make sure the backup was restored successfully. It checks for things like making sure the database has tables. You can add your own custom checks as well that you can configure to run after a backup:restore:

namespace App\HealthChecks;

use Wnx\LaravelBackupRestore\PendingRestore;
use Wnx\LaravelBackupRestore\HealthChecks\HealthCheck;

class MyCustomHealthCheck extends HealthCheck
{
    public function run(PendingRestore $pendingRestore): Result
    {
        $result = Result::make($this);

        // We assume that your app generates sales every day.
        // This check ensures that the database contains sales from yesterday.
        $newSales = \App\Models\Sale::query()
            ->whereBetween('created_at', [
                now()->subDay()->startOfDay(),
                now()->subDay()->endOfDay()
            ])
            ->exists();

        // If no sales were created yesterday, we consider the restore as failed.
        if ($newSales === false) {
            return $result->failed('Database contains no sales from yesterday.');
        }
        return $result->ok();
    }
}

Be sure to check out the package's readme for an example of a GitHub action you can use to validate your backup integrity incrementally.

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297