1. Go to this page and download the library: Download wnx/laravel-backup-restore library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wnx / laravel-backup-restore example snippets
return [
/**
* Health checks are run after a given backup has been restored.
* With health checks, you can make sure that the restored database contains the data you expect.
* By default, we check if the restored database contains any tables.
*
* You can add your own health checks by adding a class that extends the HealthCheck class.
* The restore command will fail, if any health checks fail.
*/
'health-checks' => [
\Wnx\LaravelBackupRestore\HealthChecks\Checks\DatabaseHasTables::class,
],
/**
* psql executes backslash meta-commands it reads from a dump, and `\!` runs
* a shell command. Dumps are therefore scanned and refused if they contain
* a meta-command that pg_dump does not itself emit.
*
* Set this to true to hand meta-commands to psql anyway. Only do that for
* dumps you trust.
*/
'allow_psql_meta_commands' => false,
/**
* The directory holding the database clients used to import a dump: mysql,
* mariadb, psql and pg_restore. Leave this empty when they are on the PATH
* of the PHP process, which is the usual case.
*
* Set one path for every connection:
*
* 'import_binary_path' => '/opt/homebrew/opt/mysql-client/bin',
*
* or one per connection, when the clients live in different places:
*
* 'import_binary_path' => [
* 'mysql' => '/opt/homebrew/opt/mysql-client/bin',
* 'pgsql' => '/Applications/Postgres.app/Contents/Versions/17/bin',
* ],
*
* When this is empty, the connection's dump.dump_binary_path in
* config/database.php is used instead. That key belongs to
* spatie/laravel-backup and points at the dump binaries rather than the
* import ones; reading it is deprecated and will stop in the next major
* version.
*/
'import_binary_path' => env('BACKUP_RESTORE_IMPORT_BINARY_PATH', ''),
];
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();
}
}