PHP code example of mahmoud-mhamed / laravel-backup-station
1. Go to this page and download the library: Download mahmoud-mhamed/laravel-backup-station 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/ */
mahmoud-mhamed / laravel-backup-station example snippets
'schedule' => [
'enabled' => true,
'frequency' => 'daily', // hourly|daily|twiceDaily|monthly|cron
'time' => '02:00',
'days' => ['*'], // every day; or ['monday','wednesday','friday'], or [1,3,5]
'day_of_month' => 1, // used by frequency=monthly
'cron' => '0 2 * * *',
],
'storage' => [
'disk' => env('BACKUP_STATION_DISK'), // null = filesystems.default; or 's3', 'minio', 'spaces'…
'path' => env('BACKUP_STATION_PATH', 'backup-station'),
],
'notifications' => [
'on_success' => ['enabled' => true, 'channels' => ['log']],
'on_failure' => ['enabled' => true, 'channels' => ['log', 'mail']],
'channels' => [
'mail' => [
// Either a literal array or a comma-separated env value.
'to' => ['[email protected]', '[email protected]'],
// or: 'to' => env('BACKUP_STATION_MAIL_TO'),
'from' => env('BACKUP_STATION_MAIL_FROM', env('MAIL_FROM_ADDRESS')),
'mailer' => env('BACKUP_STATION_MAILER', env('MAIL_MAILER')),
'queue' => true, // async by default
],
'slack' => [
'webhook' => env('BACKUP_STATION_SLACK_WEBHOOK', env('LOG_SLACK_WEBHOOK_URL')),
'queue' => false, // webhook is fast; sync is fine
],
'telegram' => [
'bot_token' => env('BACKUP_STATION_TELEGRAM_BOT_TOKEN'),
'chat_id' => env('BACKUP_STATION_TELEGRAM_CHAT_ID'),
'queue' => true, // async by default
],
'discord' => [
'webhook' => env('BACKUP_STATION_DISCORD_WEBHOOK'),
'queue' => true, // async by default
],
],
],
'retention' => [
'max_backups' => 30, // hard cap (0 = unlimited)
'keep_for_days' => 14, // delete older than (0 = forever)
'monthly_keep' => [
'enabled' => true,
'day' => 1, // keep the 1st of each month
'keep_months' => 12, // for 12 months
],
],
use MahmoudMhamed\BackupStation\Contracts\BackupConnectionProvider;
class MyBackupConnectionProvider implements BackupConnectionProvider
{
/** Connection names a full run should cover. */
public function connections(): array
{
return ['mysql', ...Tenant::all()->map(fn ($t) => $t->database()->getName())];
}
/** DB config for names Laravel doesn't know (same shape as database.connections.*). */
public function configFor(string $name): ?array
{
return Tenant::findByDatabase($name)?->database()->connection();
}
/** Human labels shown in the dashboard (dropdowns, Databases page). */
public function labels(): array
{
return ['mysql' => 'Central', /* db name => tenant name, … */];
}
}
// config/backup-station.php
'scope' => [
// 'ui' — manage from the dashboard Databases page (stored in
// settings.json on the storage disk). Default.
// 'config' — the arrays below are authoritative; dashboard toggles
// are disabled.
'source' => env('BACKUP_STATION_SCOPE_SOURCE', 'ui'),
'only' => [], // when non-empty, scheduled runs cover ONLY these
'exclude' => [], // otherwise these are skipped on scheduled runs
],
use MahmoudMhamed\BackupStation\Facades\BackupStation;
BackupStation::runBackup(); // manual run — covers every connection
BackupStation::runBackup(scheduled: true); // respects the automatic-backup scope
BackupStation::runBackup('mysql'); // one explicit connection
BackupStation::applyRetentionPolicy(); // returns deleted IDs
BackupStation::stats(); // dashboard stats
BackupStation::allBackupConnections(); // every configured connection
BackupStation::backupConnections(); // connections a scheduled run covers
BackupStation::databasesSizeSummary(); // combined live size of all databases