Installation
composer require dizda/cloud-backup-bundle
Add to config/bundles.php:
Dizda\CloudBackupBundle\DizdaCloudBackupBundle::class => ['all' => true],
Configure Cloud Provider
Edit config/packages/dizda_cloud_backup.yaml (or create if missing):
dizda_cloud_backup:
cloud:
service: dropbox # or cloudapp, s3, googledrive
# Provider-specific config (e.g., Dropbox API key)
dropbox:
app_key: "%env(DROPBOX_APP_KEY)%"
app_secret: "%env(DROPBOX_APP_SECRET)%"
First Backup Command
php bin/console dizda:cloud-backup:dump --database=mysql --cloud=dropbox
Flags:
--database: mysql, mongodb, or postgresql--cloud: Target cloud service--all-databases: Dump all databases (MySQL only)config/packages/dizda_cloud_backup.yaml (or app/config/config.yml in Symfony 2.x).php bin/console list dizda to see available backup commands.var/log/dev.log for backup execution details..env.php bin/console dizda:cloud-backup:dump --database=mysql --cloud=dropbox --path="/Backups/MyApp"
0 2 * * * cd /path/to/project && php bin/console dizda:cloud-backup:dump --database=mysql --cloud=dropbox --path="/Backups/MyApp" >> /var/log/myapp_backup.log 2>&1
config/packages/dizda_cloud_backup.yaml:
dizda_cloud_backup:
backups:
- name: "production_backup"
databases:
- { type: mysql, host: "127.0.0.1", user: "root", password: "%env(DB_PASSWORD)%" }
- { type: mongodb, host: "mongodb://user:pass@localhost:27017" }
clouds:
- { service: dropbox, path: "/Backups/Prod" }
- { service: s3, bucket: "my-backups", prefix: "prod/" }
php bin/console dizda:cloud-backup:run production_backup
Pre/Post Backup Hooks
Override the BackupCommand to add logic before/after backup:
// src/Command/CustomBackupCommand.php
namespace App\Command;
use Dizda\CloudBackupBundle\Command\BackupCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CustomBackupCommand extends BackupCommand {
protected function execute(InputInterface $input, OutputInterface $output) {
$this->logPreBackup($output);
parent::execute($input, $output);
$this->logPostBackup($output);
}
}
Register as a service in config/services.yaml and replace the original command.
Custom Backup Paths
Use the --path flag or extend the BackupManager to dynamically generate paths:
dizda_cloud_backup:
backup_path: "%kernel.project_dir%/backups/%database%_%date%"
Compression Enable gzip compression in config:
dizda_cloud_backup:
compression: true
Database-Specific Config For PostgreSQL, exclude system databases:
dizda_cloud_backup:
databases:
postgresql:
exclude: ["template0", "template1", "postgres"]
| Provider | Key Configuration | Notes |
|---|---|---|
| Dropbox | app_key, app_secret, access_token |
Use OAuth2 for production. |
| CloudApp | api_key, api_secret |
Requires CloudApp-API-PHP-wrapper. |
| S3 | bucket, access_key, secret_key |
Works with KnpGaufretteBundle or OneupFlysystemBundle. |
| Google Drive | client_id, client_secret, refresh_token |
Use Google API PHP Client. |
Deprecated Symfony 2.x
app/config/config.yml with config/packages/dizda_cloud_backup.yaml.Cloud Provider Dependencies
dropbox/dropbox-sdk (auto-installed via Composer).matthiasplappert/cloudapp-api-php-wrapper (not auto-installed).
Fix: Add to composer.json:
"require": {
"matthiasplappert/cloudapp-api-php-wrapper": "^1.0"
}
knplabs/knp-gaufrette-bundle or oneup/flysystem-bundle (not auto-installed).MongoDB Dump Path Issues
mongodump is in PATH or specify its location in config:
dizda_cloud_backup:
mongodb:
mongodump_path: "/usr/local/bin/mongodump"
Large File Uploads
dizda_cloud_backup:
chunk_size: 20971520 # 20MB chunks
Enable Verbose Logging
php bin/console dizda:cloud-backup:dump --verbose --database=mysql --cloud=dropbox
Or configure Monolog in config/packages/monolog.yaml:
monolog:
handlers:
main:
level: debug
Check Backup Files Locally
Backups are temporarily stored in var/backups/ before upload. Inspect files here to debug dump failures.
Cloud Provider Errors
access_token expiration (tokens expire after ~4 hours).
Fix: Use a refresh token or implement OAuth2 flow.refresh_token is valid (tokens expire; regenerate if needed).Environment Variables
Always use %env() for sensitive data (e.g., app_secret):
dizda_cloud_backup:
cloud:
dropbox:
app_key: "%env(DROPBOX_APP_KEY)%"
Define in .env:
DROPBOX_APP_KEY=your_key_here
Database Connection Issues
dizda_cloud_backup:
databases:
mysql:
host: "remote-db.example.com"
port: 3306
Path Permissions
Ensure var/backups/ is writable:
mkdir -p var/backups
chmod -R 775 var/backups
Custom Backup Strategies
Extend Dizda\CloudBackupBundle\Backup\BackupManager to add:
**
How can I help you explore Laravel packages today?