Backups for Laravel that you can actually restore: database and files, kept in more than one place, checked after they are written, with a restore that takes a safety copy first.
بالعربي: docs/ar/README.md
Most backup tools stop at "the file was written". The interesting part is what comes after: did the second copy land, were the old ones cleaned up, is the stored file still the file you wrote, and does the restore work.
- Database, files, or both, in one archive, so a restore cannot half-succeed with the wrong two files.
- Several destinations. A local folder, an optional second folder, FTP, and any Laravel disk (S3, Spaces, R2, B2). One destination being down does not lose the backup, and the backup says so when it happens.
- No shell needed for MySQL, MariaDB and SQLite: the dump is written in PHP over PDO and streamed, so a large database does not fill PHP's memory. PostgreSQL uses
pg_dumpandpsql. - Safe restore. Before any restore, a full protected copy of what is live is taken, kept outside every destination. If it cannot be taken, the restore does not start. If the restore dies,
backkeep:recoverputs the site back. - Verification. Every backup stores a checksum.
backkeep:verifyre-reads each stored copy on each destination and compares. - Health checks and alerts.
backkeep:doctorand the Health page tell you when backups stopped running. Mail and Slack, Discord or Telegram webhooks tell you when one fails. - Retention that runs itself, encryption (AES-256-GCM), a schedule, and an optional admin UI where every option is visible and editable.
- PHP 8.1 or newer
- Laravel 10, 11, 12 or 13
ext-zipfor file backupsext-pdoand the driver for your database- PostgreSQL only: the
pg_dumpandpsqlbinaries (same major version as the server or newer) - FTP:
composer require league/flysystem-ftp. S3 and other disks: the Flysystem adapter Laravel asks for (league/flysystem-aws-s3-v3for S3).
composer require elbanbydev/backkeep
php artisan vendor:publish --tag=backkeep-config
php artisan vendor:publish --tag=backkeep-migrations
php artisan migrate
php artisan backkeep:testbackkeep:test checks that the backup folder is writable, the zip extension is there, the database is reachable and a key is set if you asked for encryption.
Then take a backup and prove you can restore it, on a copy of your data first:
php artisan backkeep:run full
php artisan backkeep:list
php artisan backkeep:verify
php artisan backkeep:restore 1 --type=database --dry-run # shows what it would doA five minute walkthrough is in docs/quickstart.md.
Everything lives in config/backkeep.php, and every option has an environment variable (BACKKEEP_...). Defaults are safe. Passwords, keys and webhook URLs are only ever set in config or .env, never in the UI.
The options you will touch first:
| What | Env var | Default |
|---|---|---|
| Backup folder | BACKKEEP_LOCAL_PATH |
storage/backkeep |
| Automatic second copy | BACKKEEP_LOCAL_SECONDARY_PATH |
none |
| Keep the newest N | BACKKEEP_MAX_BACKUPS |
3 |
| Run on a schedule | BACKKEEP_SCHEDULE (_FREQUENCY, _HOUR, _MINUTE, _TYPE) |
off |
| Encrypt archives | BACKKEEP_ENCRYPTION, BACKKEEP_ENCRYPTION_KEY |
off |
| Mail on success or failure | BACKKEEP_MAIL, BACKKEEP_MAIL_TO |
off |
| One webhook | BACKKEEP_WEBHOOK_URL, BACKKEEP_WEBHOOK_DRIVER (slack, discord, telegram), BACKKEEP_WEBHOOK_CHAT_ID |
none |
| Admin UI | BACKKEEP_UI_ENABLED |
off |
| Hours before a backup counts as missing | BACKKEEP_STALE_AFTER_HOURS |
48 |
The config file is commented and lists the rest (queue, lock, timeouts, restore, tables).
php artisan backkeep:run # full: database + files
php artisan backkeep:run database
php artisan backkeep:run files --environment=staging
php artisan backkeep:run full --queue # hand it to the queueFrom code:
use Backkeep\Facades\Backkeep;
$backup = Backkeep::run('full', 'production');
$backup->status; // completed / failed
$backup->humanSize(); // "42.10 MB"
$backup->logs; // every step, in orderA failed run does not throw into a request: the row is marked failed with the error, the log says which step gave up, and the alert goes out. backkeep:run exits non-zero so cron or a deploy script notices. A run that stored the backup on some destinations but not all is completed with a warning, and backkeep:doctor keeps flagging it until the next good run.
'destinations' => [
'local' => ['enabled' => true, 'path' => storage_path('backkeep'), 'secondary_path' => '/mnt/drive/backkeep'],
'ftp' => ['enabled' => true, 'host' => env('BACKKEEP_FTP_HOST'), 'path' => '/backups' /* , username, password */],
'disk' => ['enabled' => true, 'disk' => 's3', 'path' => 'backkeep'],
'disks' => [ // any number of named disks
'r2' => ['disk' => 'r2', 'path' => 'backkeep', 'attempts' => 3],
],
],- The FTP folder is created on the first write. It is relative to the login directory.
- The
diskdestination works with anything inconfig/filesystems.php. For S3-compatible services (MinIO, R2, Spaces) set the endpoint anduse_path_style_endpointon the disk. - Check them before you need them:
php artisan backkeep:destinationswrites a tiny probe file to each one, reads it back and deletes it. The same test is a button on the Health page. - Restore and verify use the destination a backup was recorded on first, and fall back to the others that hold a copy.
php artisan backkeep:restore 12 --type=full --forceThe types are database, files and full. Without --force nothing happens, and --dry-run shows the steps without changing anything.
What a restore does, in order:
- Takes the lock and (by default) puts the app in maintenance mode.
- Takes a protected copy of the live database and files into
backkeep.restore.safety_path, outside every destination. If this fails, the restore does not start. - Pulls the backup, decrypts it, checks the checksum and the archive paths, runs the SQL and copies the files back.
- Brings the app back up and keeps the protected copy until you delete it.
If the process dies midway, the app stays in maintenance mode and a marker is left. Then:
php artisan backkeep:recover # what happened
php artisan backkeep:recover --restore-safety --force # put the state back from the protected copy
php artisan backkeep:recover --lift # just bring the app back up
php artisan backkeep:protected list # protected copies and their sizesNotes:
- A restore replaces the database contents. Tables created after the backup stay unless you set
BACKKEEP_RESTORE_DROP_UNKNOWN_TABLES=true(MySQL and MariaDB only), which makes the database match the backup exactly. - MySQL and MariaDB dumps leave out
sessions,cacheandcache_locksby default, so a restore does not log everyone out. Changedatabase.exclude_tablesif you want them. - After restoring SQLite the connection is reopened for you.
- Protected copies are never deleted automatically.
php artisan backkeep:doctor # last backup age, failures, destinations, disk space, schedule
php artisan backkeep:verify # re-read each stored copy on each destination and compare checksums
php artisan backkeep:destinations
php artisan backkeep:notify-test # sends a test mail and a test message to every webhookWebhooks post {"text": ...} (Slack), {"content": ...} (Discord) or {"chat_id": ..., "text": ...} (Telegram). For several webhooks list them under monitoring.webhooks. A webhook that fails does not fail the backup, but it is logged and backkeep:notify-test shows it.
'retention' => ['max_count' => 3, 'auto_cleanup' => true, 'keep_failed' => true],
'schedule' => ['enabled' => true, 'frequency' => 'daily', 'hour' => 22, 'minute' => 15, 'type' => 'full'],
'archive' => ['encryption' => ['enabled' => true, 'key' => env('BACKKEEP_ENCRYPTION_KEY')]],php artisan backkeep:clean --dry-runshows what retention would delete. A backup is only removed from the list once every stored copy was removed, so a destination that is down never leaves an orphan file behind.backkeep:delete {id} --forgetdrops the record anyway.- The schedule registers on Laravel's scheduler, so your usual
schedule:runcron is enough. - Encryption is AES-256-GCM in 1 MiB authenticated chunks. Keep the key somewhere that is not the backup. Lose the key and the backup is gone.
BACKKEEP_UI_ENABLED=trueOff by default, mounted at /backkeep behind ['web', 'auth']. You get the backup list with a log per backup, restore behind a typed confirmation, the protected copies (keep, roll back, delete), a Health page (checks plus a button that tests every destination) and Settings in eight tabs. Every option in config/backkeep.php is editable there except secrets (FTP login, encryption key, webhook URLs, named disks) and values fixed at boot (routes, middleware, table names), which show read only. Values saved in the UI go to storage/app/backkeep/settings.json and are laid over the config; .env is never rewritten. Details: docs/branches/admin-ui.md.
Put the UI behind your own authorization. A page that can restore a database is only as safe as the middleware in front of it.
Backkeep::run('database');
Backkeep::queue('full');
Backkeep::backups(['status' => 'completed'], 50);
Backkeep::stats();
Backkeep::restore(12, 'database', force: true);
Backkeep::delete(12);
Backkeep::clean(dryRun: true);
Backkeep::check();Events: BackupStarted, BackupCompleted, BackupFailed, RestoreStarted, RestoreCompleted, RestoreFailed.
| Command | What it does |
|---|---|
backkeep:run {type} |
Take a backup: database, files or full |
backkeep:list, backkeep:stats |
List backups, counts and sizes |
backkeep:restore {id} |
Restore, behind --force; --dry-run to preview |
backkeep:recover |
Inspect and clean up after a restore that did not finish |
backkeep:protected |
List or delete the protected copies |
backkeep:verify |
Check stored copies against their checksum |
backkeep:delete {id} |
Delete a backup and every stored copy |
backkeep:clean |
Apply retention now |
backkeep:test, backkeep:doctor |
Is this server, and the backup system, healthy |
backkeep:destinations |
Prove every destination takes a file |
backkeep:notify-test |
Test mail and webhooks |
Tested against real servers (not mocks), restoring over a live database and comparing the data afterwards: MySQL 8.4, MariaDB 10.11, PostgreSQL 14 and SQLite, with unicode, quotes, binary, JSON, NULLs, foreign keys, views and sequences, and a 500,000 row table (about 125 MB of data) restored with 44 MB of PHP memory. FTP against a real FTP server and S3 through an S3-compatible server. Webhook payloads were captured by a local receiver, so the exact HTTP request is verified, but not against the real Slack, Discord or Telegram services. CI runs Pint, PHPStan level 8 and Pest on PHP 8.1 to 8.5 and on Laravel 10, 11, 12 and 13, plus a job that backs up and restores a real MySQL 8.4, MariaDB 10.11 and PostgreSQL 16.
Said plainly:
- No incremental backups. Every run is a full backup.
- MySQL and MariaDB are restored by running the dump statement by statement in PHP. That is portable and streamed, but a very large database may restore faster with the native client (not measured here). Set
database.connectionto a scratch connection to rehearse. - PostgreSQL needs
pg_dumpandpsql. A newerpg_dumpthan the server is fine: settings it writes that an older server does not know (such astransaction_timeoutfrompg_dump17 into PostgreSQL 16) are dropped before the restore runs. The dump in storage is never changed. - No per-table backup or restore. The unit is the whole database.
drop_unknown_tablesis MySQL and MariaDB only.- Not tested: Oracle, SQL Server, real AWS S3, SFTP, and databases in the tens of gigabytes. Open an issue if you hit one.
composer test # Pest
composer analyse # PHPStan level 8
composer check # Pint, PHPStan, PestMIT. See LICENSE.md.