Skip to content

Conversation

inserve-paul
Copy link

See discussion: #1900

Added an option to reload the configuration. For e.g. when used in a multi tenancy environment where the command is called from another command and the config has been changed for the specific tenant.

…ancy environment and the command is called from another command and the config has been changed.
@inserve-paul
Copy link
Author

@freekmurze Would you like to take a look at this PR? Thank you!

@zfm-andreasmatuszewski
Copy link

Any updates here? @freekmurze

@freekmurze
Copy link
Member

Could you add a test to prove that the option works. Could you also update the docs?

@steffensatrapa
Copy link

steffensatrapa commented Aug 3, 2025

Thanks for your PR — it pointed me in the right direction.
I have several backup configurations that I used to load dynamically in a BackupJob. However, after upgrading to v9, this no longer worked.

Here are a couple of suggestions:

  1. Extend the --reload-config= option — this is what I’m using now to load specific configurations:
protected $signature = 'backup:run {--filename=} {--only-db} {--db-name=*} {--only-files} {--only-to-disk=} {--disable-notifications} {--timeout=} {--tries=} {--reload-config=}';
...
public function handle(): int
{
    if ($this->option('reload-config')) {
        $this->config = Config::fromArray(config($this->option('reload-config') ?? 'backup'));
    }
     ...
}
  1. Don’t forget to extend the other backup commands as well, like backup:clean, which I also had to modify.

inserve-paul and others added 2 commits August 12, 2025 10:55
@inserve-paul
Copy link
Author

Could you add a test to prove that the option works. Could you also update the docs?

@freekmurze I've updated the PR, added documentation and a test


foreach ($tenants as $tenant) {
config(['backup.backup.destination.filename_prefix' => $tenant.'_']);
$this->call('backup:run', ['--timeout' => 120, '--config' => 'backup']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid I don't understand the example fully.

I was expecting that you could use another back config with something like this

php artisan backup:run --config=tenant1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better (my use-case):

Running Backups with Specific Configuration

If you want to back up different areas of your Laravel application separately – for example with different schedules, database connections, filesystem disks, or cleanup settings – you can create custom backup configuration files.

Example:

Additional config files placed in the config/ directory:

  • config/backup_database.php
  • config/backup_invoices.php
  • config/backup_uploads.php

You can then run backups and cleanup commands individually:

php artisan backup:run --config=backup_database
php artisan backup:clean --config=backup_database

php artisan backup:run --config=backup_invoices
php artisan backup:clean --config=backup_invoices

php artisan backup:run --config=backup_uploads
php artisan backup:clean --config=backup_uploads

This allows full flexibility in scheduling, retention, and target destinations for each backup scope.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another example is a multitenant site with multiple databases.
When running the backup I loop through all the tenants and need to reload the tenant db configuration and also specify a different backup.filename_prefix in order to save each backup in a subfolder with the tenant name

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steffensatrapa Thanks for your addition!

@freekmurze Is that example clear? In that case I will add it to the documentation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any updates here? @freekmurze

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

Successfully merging this pull request may close these issues.

5 participants