Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spatie backup command #354

Closed
luceos opened this issue Dec 21, 2017 · 1 comment
Closed

Spatie backup command #354

luceos opened this issue Dec 21, 2017 · 1 comment
Assignees

Comments

@luceos
Copy link
Contributor

luceos commented Dec 21, 2017

Thanks to @Thijmen

We need to add this to the documentation.

<?php

namespace App\Console\Commands;

use Hyn\Tenancy\Database\Connection;
use Hyn\Tenancy\Models\Website;
use Illuminate\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
     */
    public function handle()
    {
        $this->backupSystem();
        $sites = Website::all();
        foreach ($sites as $site) {
            $this->setupConfigForSite($site);
            $this->callBackupCommand();
        };
    }

    protected function backupSystem()
    {
        \Config::set('backup.backup.source.databases', ['system']);
        \Config::set('backup.backup.name', 'system-backup');
        $this->call('backup:run', ['--only-db']);
    }

    protected function setupConfigForSite(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));
    }
    

    protected function siteIncludes(Website $website)
    {
        return storage_path('app/tenancy/tenants/' . $website->uuid);
    }

    protected function callBackupCommand()
    {
        $this->call('backup:run');
    }
}
@luceos
Copy link
Contributor Author

luceos commented Dec 21, 2017

  • Code uses hardcoded path to tenant directory.
  • Doesn't use the Repository.
  • Uses facades.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants