antihero/mount-last-db-bundle
Installation
Add the bundle to your composer.json:
composer require antihero/mount-last-db-bundle
Register the bundle in config/bundles.php:
return [
// ...
Antihero\MountLastDbBundle\MountLastDbBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console config:dump-reference Antihero\MountLastDbBundle
Update .env with your remote server credentials (SMB/SFTP) and local DB details:
MOUNT_LAST_DB_REMOTE_SERVER=smb://user:pass@server/path
MOUNT_LAST_DB_LOCAL_DB=your_local_db_name
First Use Case Trigger a remote dump mount:
php bin/console mount:last-db
This fetches the latest .gz SQL dump from the remote server, decompresses it, and imports it into your local DB.
Automated Deployment Workflow
post-deploy script to sync production DB to staging/test:
php bin/console mount:last-db --env=staging
artisan scheduler for nightly syncs:
// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('mount:last-db')->daily();
}
Custom Remote Sources
Extend the bundle’s RemoteSourceInterface to support additional protocols (e.g., AWS S3):
class S3Source implements RemoteSourceInterface
{
public function fetchLatestDump(): string
{
// AWS SDK logic to fetch latest dump
}
}
Register the service in services.yaml:
services:
Antihero\MountLastDbBundle\RemoteSource\RemoteSourceInterface: '@app.s3_source'
Conditional Mounting Check if a dump exists before mounting (e.g., in a CI/CD pipeline):
php bin/console mount:last-db:check
Service Provider Binding
Bind the bundle’s services in AppServiceProvider for custom logic:
public function boot()
{
$this->app->bind(
\Antihero\MountLastDbBundle\Service\DbService::class,
function ($app) {
return new CustomDbService($app);
}
);
}
Event Listeners Trigger actions post-mount (e.g., cache clearing):
// app/Providers/EventServiceProvider.php
protected $listen = [
'mount.last-db.success' => [
\App\Listeners\ClearCache::class,
],
];
Permission Issues
.env have read access to the remote dump directory.mysql.user privileges).File Locking
# config/packages/antihero_mount_last_db.yaml
mount_last_db:
retry_attempts: 3
retry_delay: 60
Large Dumps
php.ini:
memory_limit = 2G
max_execution_time = 3600
php bin/console mount:last-db --env=local -v
php bin/console mount:last-db:fetch-only
Custom Filename Patterns Override the dump filename regex in config:
mount_last_db:
dump_pattern: '^dump_(\d{4}-\d{2}-\d{2}).sql.gz$'
Pre/Post-Mount Hooks Use Symfony events to inject logic:
// src/EventListener/MountListener.php
public function onMountSuccess(MountSuccessEvent $event)
{
// Run custom logic after mount
}
Register the listener in services.yaml:
services:
App\EventListener\MountListener:
tags:
- { name: kernel.event_listener, event: mount.last-db.success }
Database-Specific Quirks
--single-transaction to mysql CLI flags to avoid locks:
mount_last_db:
mysql_flags: ['--single-transaction']
pg_restore for custom formats:
mount_last_db:
db_engine: pgsql
restore_flags: ['--clean', '--if-exists']
How can I help you explore Laravel packages today?