Installation
composer require --dev desarrolla2/download-bundle
Register the bundle in AppKernel.php (Symfony) or config/app.php (Laravel) only for dev environment:
// Laravel (config/app.php)
if (app()->environment('local')) {
$provider = new Desarrolla2\DownloadBundle\DownloadServiceProvider();
if (method_exists($provider, 'register')) {
$provider->register();
}
}
Configuration
Add to .env (Laravel) or config/packages/dev.yml (Symfony):
DOWNLOAD_USER=deploy_user
DOWNLOAD_HOST=production_host_or_ip
DOWNLOAD_TIMEOUT=300
DOWNLOAD_DB_DIR=/var/data/databases
DOWNLOAD_DB_REMOTE_HOST=production_database_host
DOWNLOAD_ONLY_STRUCTURE=mail_history
First Use Case Trigger a download via Artisan (Laravel) or Symfony CLI:
php artisan download:fetch
This will:
download/folders)..env has DB_DATABASE pointing to the restored file).Scheduled Syncs Add a cron job (Linux) to sync data nightly:
0 3 * * * cd /path/to/project && php artisan download:fetch >> /var/log/download.log 2>&1
Log output to debug SSH/DB issues.
Conditional Syncs Use a custom command to sync only specific tables/folders:
php artisan download:fetch --tables=users,products --folders=uploads
(Note: Verify if the package supports CLI flags; extend via custom commands if needed.)
Integration with Deployments Hook into Laravel Forge/Envoyer or Symfony Deployer:
# deployer.php (Symfony)
task('deploy:post')->after('deploy:update_code')->do(function () {
run('cd {{release_path}} && php bin/console download:fetch');
});
Database-Specific Handling For large databases, split the dump into chunks:
// Customize the service (if extendable)
$this->app->make('download')->setChunkSize(100); // Hypothetical method
~/.ssh/id_rsa.pub is added to authorized_keys on the remote host..env to point to the restored file:
DB_CONNECTION=mysql
DB_DATABASE=/var/data/databases/production.sql
(Note: Use DB_SOCKET or DB_HOST if restoring to a local MySQL instance.)755 permissions:
// Post-sync fix (custom command)
Artisan::call('storage:link');
chmod('/path/to/folders', 0755);
Linux-Only Limitation
Database Restore Quirks
mysql -u root -p < production.sql
mysqldump --max_allowed_packet=1G on the remote host.Configuration Overrides
config/packages/dev.yml in Symfony.config_dev.php to merge settings:
return [
'download' => array_merge(
require __DIR__.'/parameters.yml',
$_ENV
),
];
SSH Timeouts
timeout: 300 may be too short for large transfers.1800 (30 mins) or monitor with ssh -vvv.Folder Exclusions
.git or node_modules by default..env:
DOWNLOAD_EXCLUDE_FOLDERS=.git,node_modules,vendor
php artisan download:fetch --verbose
ssh deploy_user@production_host "ls -lah /path/to/dumps/"
deploy_user has read access to:
uploads/).Custom Commands Extend the bundle by creating a custom Artisan command:
// app/Console/Commands/SyncProduction.php
class SyncProduction extends Command {
protected $signature = 'download:sync {--tables=*} {--folders=*}';
public function handle() {
$this->call('download:fetch', [
'--tables' => $this->option('tables'),
'--folders' => $this->option('folders'),
]);
}
}
Pre/Post-Hooks
Use Laravel’s registerCommands to add logic before/after sync:
// DownloadServiceProvider.php
public function register() {
$this->app->booted(function () {
if ($this->app->runningInConsole()) {
Artisan::extend(function ($artisan) {
$artisan->resolving('command.download.fetch', function ($command) {
// Pre-sync: Backup local DB
Artisan::call('db:backup');
});
});
}
});
}
Remote Path Customization Override remote paths dynamically:
// config/packages/dev.yml
download:
database:
remote:
dump_path: '/custom/path/production_{{ date("Y-m-d") }}.sql'
How can I help you explore Laravel packages today?