zenstruck / backup-bundle
Symfony Bundle that wraps backup commands
Fund package maintenance!
kbond
Installs: 7 855
Dependents: 0
Suggesters: 0
Security: 0
Stars: 17
Watchers: 4
Forks: 3
Open Issues: 2
Type:symfony-bundle
Requires
- php: >=8.0
- symfony/framework-bundle: ^5.4|^6.0|^7.0
- zenstruck/backup: ^2.0
Requires (Dev)
- matthiasnoback/symfony-dependency-injection-test: ^4.3|^5.1
- phpunit/phpunit: ^9.6
- symfony/console: ^5.4|^6.0|^7.0
- symfony/phpunit-bridge: ^6.1|^7.0
- symfony/yaml: ^5.4|^6.0|^7.0
README
This bundle allows creating and managing backups in a Symfony application. It is a wrapper for zenstruck/backup.
Installation
- Install with composer:
composer require zenstruck/backup-bundle
-
Enable the bundle: This Step is only needed if you are not using Symfony Flex.
// config/bundles.php return [ // ... Zenstruck\BackupBundle\ZenstruckBackupBundle::class => ['all' => true], ];
Configuration
In your config/packages/zenstruck_backup.yaml
add at least one source, namer, processor, and destination as well as a profile.
Example:
zenstruck_backup: sources: database: mysqldump: database: my_database files: rsync: source: "%kernel.project_dir%/public/files" additional_options: - --exclude=_cache/ namers: daily: timestamp: format: d prefix: mysite- snapshot: timestamp: prefix: mysite- processors: zip: { zip: ~ } destinations: s3: s3cmd: bucket: "s3://foobar/backups" profiles: daily: scratch_dir: "%kernel.project_dir%/cache/backup" sources: [database, files] namer: daily processor: zip destinations: [s3]
Commands
Run Backup Command
Usage:
zenstruck:backup:run [--clear] [<profile>]
Arguments:
profile The backup profile to run (leave blank for listing)
Options:
--clear Set this flag to clear scratch directory before backup
NOTES:
- Add
-vv
to see the log. - For long running backups, it may be required to increase the
memory_limit
in yourbin/console
. - Running the command without a profile will list available profiles.
Examples (with the above configuration):
-
Create a backup at:
s3://foobar/backups/mysite-{day-of-month}
bin/console zenstruck:backup:run daily
-
Create a backup at:
s3://foobar/backups/mysite-{YYYYMMDDHHMMSS}
bin/console zenstruck:backup:run snapshot
List Existing Backups
Usage:
zenstruck:backup:list [<profile>]
Arguments:
profile The backup profile to list backups for (leave blank for listing)
NOTE: Running the command without a profile will list available profiles.
Full Default Config
zenstruck_backup: namers: # Prototype name: simple: name: backup timestamp: format: YmdHis prefix: '' timezone: ~ processors: # Prototype name: zip: options: '-r' timeout: 300 gzip: options: '-czvf' timeout: 300 sources: # Prototype name: mysqldump: database: ~ # Required host: ~ user: root password: null ssh_host: null ssh_user: null ssh_port: 22 timeout: 300 rsync: source: ~ # Required timeout: 300 additional_options: [] default_options: # Defaults: - -acrv - --force - --delete - --progress - --delete-excluded destinations: # Prototype name: stream: directory: ~ # Required flysystem: filesystem_service: ~ # Required s3cmd: bucket: ~ # Required, Example: s3://foobar/backups timeout: 300 profiles: # Prototype name: scratch_dir: '%kernel.cache_dir%/backup' sources: [] # Required, can be a string namer: ~ # Required processor: ~ # Required destinations: [] # Required, can be a string