Skip to content

Commit

Permalink
feat(backup): added backup strategy (#3)
Browse files Browse the repository at this point in the history
* refactor(connection): refactored connection model namespace

* feat(backup): updated connection configuration to backup

* tests: added unit tests for generic factory

* tests(backup): added unit tests backup registry

* feat(backup): added max backup files handle in backup command

* tests(backup): added keep other backup files tests on backup command
  • Loading branch information
SVillette authored Apr 21, 2022
1 parent d91f5ea commit 8f5b4d5
Show file tree
Hide file tree
Showing 35 changed files with 1,399 additions and 534 deletions.
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,35 @@ to `config/packages` directory.

```yaml
symandy_database_backup:
connections:
# Multiple connections can be added
backups:
foo:
# driver: !php/const \Symandy\DatabaseBackupBundle\Model\ConnectionDriver::MySQL
driver: mysql

# Usage of environment variables as parameters is recommended for connections configuration
configuration:
user: "%app.foo_db_user%"
password: "%app.foo_db_password%"
host: 127.0.0.1 # Already the default value, don't need to be added
port: 3306 # Already the default value, don't need to be added
databases: [foo, bar, baz] # Will only back up these databases
connection:
# driver: !php/const \Symandy\DatabaseBackupBundle\Model\ConnectionDriver::MySQL
driver: mysql

# Usage of environment variables as parameters is recommended for connections configuration
configuration:
user: "%app.foo_db_user%"
password: "%app.foo_db_password%"
host: 127.0.0.1 # Already the default value, don't need to be added
port: 3306 # Already the default value, don't need to be added
databases: [foo, bar, baz] # Will only back up these databases
strategy:
max_files: 5 # Number of files kept after a backup (per database)
# backup_directory: "/var/www/backups" # The directory must be created and must have the right permissions
backup_directory: "%kernel.project_dir%/backups"
# backup_directory: ~ # The current directory will be used if no value is passed
```

### Drivers

Only the `mysql` driver is currently available.

## Usage
Once the connections are configured, you only have to run the following command to generate the dumped databases files:
Once the backups are configured, you only have to run the following command to generate the dumped databases backup files:

```shell
php bin/console symandy:databases:backup
```

It will generate one file by connection in the format `<connection_name>-<current_year>-<current_month>-<current_day>.sql`.
It will generate one file by database in the format `<backup_name>-<database>-<current_year>-<current_month>-<current_day>.sql`.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"symfony/http-kernel": "^6.0",
"symfony/dependency-injection": "^6.0",
"symfony/config": "^6.0",
"symfony/process": "^6.0"
"symfony/process": "^6.0",
"symfony/serializer": "^6.0",
"symfony/property-access": "^6.0"
},
"require-dev": {
"phpstan/phpstan": "^1.5",
Expand Down
Loading

0 comments on commit 8f5b4d5

Please sign in to comment.