Skip to content

Spatie backup command #21

Description

@bkintanar

Moved from tenancy/multi-tenant#354

Thanks to @Thijmen

We need to add this to the documentation.

<?phpnamespaceApp\Console\Commands;
useHyn\Tenancy\Database\Connection;
useHyn\Tenancy\Models\Website;
useIlluminate\Console\Command;
class BackupCommand extends Command
{
/** * The name and signature of the console command. * * @var string */protected$signature = 'app:backup';
/** * The console command description. * * @var string */protected$description = 'Backup all the tenants and system';
/** * Execute the console command. * * @return mixed */publicfunctionhandle()
{
$this->backupSystem();
$sites = Website::all();
foreach ($sitesas$site) {
$this->setupConfigForSite($site);
$this->callBackupCommand();
};
}
protectedfunctionbackupSystem()
{
\Config::set('backup.backup.source.databases', ['system']);
\Config::set('backup.backup.name', 'system-backup');
$this->call('backup:run', ['--only-db']);
}
protectedfunctionsetupConfigForSite(Website$website)
{
$connection = app(Connection::class);
$connection->set($website);
\Config::set('backup.backup.source.databases', ['tenant']);
\Config::set('backup.backup.name', 'tenant-' . $website->uuid);
\Config::set('backup.backup.source.files.include', $this->siteIncludes($website));
}
protectedfunctionsiteIncludes(Website$website)
{
returnstorage_path('app/tenancy/tenants/' . $website->uuid);
}
protectedfunctioncallBackupCommand()
{
$this->call('backup:run');
}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions