Skip to content

Commit 302051a

Browse files
committed
no issue - much better configuration
1 parent f31402f commit 302051a

38 files changed

+976
-665
lines changed

config/db_tools.standalone.sample.yaml

Lines changed: 64 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -9,104 +9,82 @@
99

1010
# Working directory is the path to which all relative file references will
1111
# be relative to. If none set, the path will be this file directory instead.
12-
workdir: /var/www/my_project/
12+
# In most cases, you will not need it.
13+
#workdir: /var/www/my_project/
1314

14-
# Database connections.
15-
# One line per connection, a single database URL, all options as query
16-
# parameters. Connections will be made using makincorpus/query-builder
17-
# which will raise exceptions when invalid options are found.
18-
# There is less configuration amplitude than using doctrine/dbal in
19-
# Symfony, yet it should be enough in most case.
20-
# In case any options or specific behaviour is missing, please file
21-
# an issue at https://github.com/makinacorpus/php-query-builder/issues
22-
connections:
23-
connection_one: "pgsql://username:password@hostname:port?version=16.0&other_option=..."
24-
connection_two: "mysql://username:password@hostname:port?version=8.1&other_option=..."
15+
# Where to put generated backups.
16+
# Root directory of the backup storage manager. Default filename
17+
# strategy will always use this folder as root path.
18+
storage_directory: ./var/db_tools
2519

26-
# If you have a single connection, you can use this syntax. In this case
27-
# the connection name will be "default".
28-
# connections: "pgsql://username:password@hostname:port?version=16.0&other_option=..."
29-
30-
# You can explicitely set which will be default connection in use when
31-
# none providen in the command line options. If you omit this configuration
32-
# value, then the first one in the list will be used.
33-
#default_connection: connection_one
34-
35-
# Using the DbToolsBundle standalone, you must provide at least
36-
# a root directory for backups.
37-
storage:
38-
# Path can be relative or absolute, Relative paths are relative to the
39-
# workdir option if specified, or from this configuration file directory
40-
# otherwise.
41-
# If none provided, the default will be the following one.
42-
root_dir: ./var/db_tools
43-
# Filename strategies. You may specify one strategy for each doctrine
44-
# connection. Keys are doctrine connection names. Values are strategy
45-
# names, "default" (or null) or omitting the connection will use the
46-
# default implementation.
47-
# If you created and registered a custom one into the container as a
48-
# service, you may simply set the service identifier. If no service
49-
# exists, and your implementation does not require parameters, simply
50-
# set the class name.
51-
#filename_strategy:
52-
# Backup filename strategy.
53-
# "default" is an alias of "datetime"
54-
#default: default
55-
# "datetime" implementation is ROOT_DIR/YYYY/MM/<connection-name>-<datestamp>.<ext>"
56-
#other_connection_strategy: datetime
57-
# Example of using a service name:
58-
#yet_another_connection: app.db_tools.filename.custom_strategy
59-
# Or a classe name:
60-
#another_one: App\DbTools\Storage\MyCustomStrategy
20+
# Filename strategies. You may specify one strategy for each doctrine
21+
# connection. Keys are doctrine connection names. Values are strategy
22+
# names, "default" (or null) or omitting the connection will use the
23+
# default implementation.
24+
# If you created and registered a custom one into the container as a
25+
# service, you may simply set the service identifier. If no service
26+
# exists, and your implementation does not require parameters, simply
27+
# set the class name.
28+
# Allowed values are:
29+
# - "default": alias of "datetime".
30+
# - "datetime": implementation is "%db_tools.storage.root_dir%/YYYY/MM/<connection-name>-<datestamp>.<ext>".
31+
# - CLASS_NAME: a class name to use that implements a strategy.
32+
# - SERVICE_ID: in Symfony context, a service registered in container that implements a strategy.
33+
#storage_filename_strategy: default
6134

62-
# When old backups are considered obsolete
35+
# When old backups are considered obsolete.
6336
# (Use relative date/time formats : https://www.php.net/manual/en/datetime.formats.relative.php)
6437
#backup_expiration_age: '6 months ago' # default '3 months ago'
6538

6639
# Timeout for backups.
67-
# backup_timeout: 1200 # default 600
40+
#backup_timeout: 1200 # default 600
6841

6942
# Timeout for restores.
70-
# restore_timeout: 2400 # default 1800
43+
#restore_timeout: 2400 # default 1800
7144

72-
# List here tables (per connection) you don't want in your backups
73-
#excluded_tables:
74-
#default: ['table1', 'table2']
45+
# List here tables (you don't want in your backups.
46+
#backup_excluded_tables: ['table1', 'table2']
7547

76-
# Specify here paths to binaries, only if the system can't find them by himself
77-
# platform are 'mysql', 'postgresql', 'sqlite'
78-
#backupper_binaries:
79-
#mariadb: '/usr/bin/mariadb-dump' # default 'mariadb-dump'
80-
#mysql: '/usr/bin/mysqldump' # default 'mysqldump'
81-
#postgresql: '/usr/bin/pg_dump' # default 'pg_dump'
82-
#sqlite: '/usr/bin/sqlite3' # default 'sqlite3'
83-
#restorer_binaries:
84-
#mariadb: '/usr/bin/mariadb' # default 'mariadb'
85-
#mysql: '/usr/bin/mysql' # default 'mysql'
86-
#postgresql: '/usr/bin/pg_restore' # default 'pg_restore'
87-
#sqlite: '/usr/bin/sqlite3' # default 'sqlite3'
48+
# Specify here paths to binaries and options, only if the system can't find
49+
# them by himself.
50+
# Default value depends upon vendor and is documented at
51+
# https://dbtoolsbundle.readthedocs.io/en/stable/configuration.html
52+
#backup_binary: '/usr/bin/pg_dump'
53+
#backup_options: '-Z 5 --lock-wait-timeout=120'
54+
#restore_binary: '/usr/bin/pg_restore'
55+
#restore_options: '-j 2 --clean --if-exists --disable-triggers'
8856

89-
# Default options to pass to the binary when backing up or restoring
90-
# a database. Those options must be defined per connection.
91-
# If you do not define some default options, here or by using the
92-
# "--extra-options" option when invoking the command, the following
93-
# ones will be used according to the database vendor:
94-
# - When backing up:
95-
# - MariaDB: --no-tablespaces
96-
# - MySQL: --no-tablespaces
97-
# - PostgreSQL: -Z 5 --lock-wait-timeout=120
98-
# - SQLite: -bail
99-
# - When restoring:
100-
# - MariaDB: None
101-
# - MySQL: None
102-
# - PostgreSQL: -j 2 --clean --if-exists --disable-triggers
103-
# - SQLite: None
104-
#backupper_options:
105-
#default: ''
106-
#another_connection: ''
107-
#restorer_options:
108-
#default: ''
109-
#another_connection: ''
57+
# If you have a single connection, you can use this syntax. In this case
58+
# the connection name will be "default".
59+
connections: "pgsql://username:password@hostname:port?version=16.0&other_option=..."
60+
61+
# Alternatively, you are allowed to have more than one connections, case
62+
# in which you might synthesize the configuration as this:
63+
#connections:
64+
# connection_one: "pgsql://username:password@hostname:port?version=16.0&other_option=..."
65+
# connection_two: "mysql://username:password@hostname:port?version=8.1&other_option=..."
66+
67+
# For advanced usage, you may also override any parameter at the connection
68+
# Each key is a connection name, all parameters above are allowed for each
69+
# unique connection.
70+
#connections:
71+
# connection_one:
72+
# # Connection URL for connecting.
73+
# # Please refer to makinacorpus/db-query-builder documentation for more information.
74+
# # Any URL built for doctrine/dbal usage should work.
75+
# # URL is the only mandatory parameter.
76+
# url: "pgsql://username:password@hostname:port?version=16.0&other_option=..."
77+
# #backup_expiration_age: '3 month ago'
78+
# # ...
79+
# connection_two:
80+
# url: "mysql://username:password@hostname:port?version=8.1&other_option=..."
81+
# backup_options: '-Z 5 --lock-wait-timeout=60'
82+
# restore_options: '-j 3 --clean'
83+
84+
# You can explicitely set which will be default connection in use when
85+
# none providen in the command line options. If you omit this configuration
86+
# value, then the first one in the list will be used.
87+
#default_connection: connection_one
11088

11189
# Update this configuration if you want to look for anonymizers in a custom folder.
11290
# These are default paths that will always be registered even if you override

config/packages/db_tools.yaml

Lines changed: 46 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,62 @@
11
db_tools:
22
# Where to put generated backups.
3-
#storage:
4-
# Root directory of the backup storage manager. Default filename
5-
# strategy will always use this folder as root path.
6-
#root_dir: '%kernel.project_dir%/var/db_tools'
3+
# Root directory of the backup storage manager. Default filename
4+
# strategy will always use this folder as root path.
5+
storage_directory: '%kernel.project_dir%/var/db_tools'
76

8-
# Filename strategies. You may specify one strategy for each doctrine
9-
# connection. Keys are doctrine connection names. Values are strategy
10-
# names, "default" (or null) or omitting the connection will use the
11-
# default implementation.
12-
# If you created and registered a custom one into the container as a
13-
# service, you may simply set the service identifier. If no service
14-
# exists, and your implementation does not require parameters, simply
15-
# set the class name.
16-
#filename_strategy:
17-
# Backup filename strategy.
18-
# "default" is an alias of "datetime"
19-
#default: default
20-
# "datetime" implementation is "%db_tools.storage.root_dir%/YYYY/MM/<connection-name>-<datestamp>.<ext>"
21-
#other_connection_strategy: datetime
22-
# Example of using a service name:
23-
#yet_another_connection: app.db_tools.filename.custom_strategy
24-
# Or a classe name:
25-
#another_one: App\DbTools\Storage\MyCustomStrategy
7+
# Filename strategies. You may specify one strategy for each doctrine
8+
# connection. Keys are doctrine connection names. Values are strategy
9+
# names, "default" (or null) or omitting the connection will use the
10+
# default implementation.
11+
# If you created and registered a custom one into the container as a
12+
# service, you may simply set the service identifier. If no service
13+
# exists, and your implementation does not require parameters, simply
14+
# set the class name.
15+
# Allowed values are:
16+
# - "default": alias of "datetime".
17+
# - "datetime": implementation is "%db_tools.storage.root_dir%/YYYY/MM/<connection-name>-<datestamp>.<ext>".
18+
# - CLASS_NAME: a class name to use that implements a strategy.
19+
# - SERVICE_ID: in Symfony context, a service registered in container that implements a strategy.
20+
#storage_filename_strategy: default
2621

27-
# When old backups are considered obsolete
22+
# When old backups are considered obsolete.
2823
# (Use relative date/time formats : https://www.php.net/manual/en/datetime.formats.relative.php)
2924
#backup_expiration_age: '6 months ago' # default '3 months ago'
3025

3126
# Timeout for backups.
32-
# backup_timeout: 1200 # default 600
27+
#backup_timeout: 1200 # default 600
3328

3429
# Timeout for restores.
35-
# restore_timeout: 2400 # default 1800
30+
#restore_timeout: 2400 # default 1800
3631

37-
# List here tables (per connection) you don't want in your backups
38-
#excluded_tables:
39-
#default: ['table1', 'table2']
32+
# List here tables (you don't want in your backups.
33+
#backup_excluded_tables: ['table1', 'table2']
4034

41-
# Specify here paths to binaries, only if the system can't find them by himself
42-
# platform are 'mysql', 'postgresql', 'sqlite'
43-
#backupper_binaries:
44-
#mariadb: '/usr/bin/mariadb-dump' # default 'mariadb-dump'
45-
#mysql: '/usr/bin/mysqldump' # default 'mysqldump'
46-
#postgresql: '/usr/bin/pg_dump' # default 'pg_dump'
47-
#sqlite: '/usr/bin/sqlite3' # default 'sqlite3'
48-
#restorer_binaries:
49-
#mariadb: '/usr/bin/mariadb' # default 'mariadb'
50-
#mysql: '/usr/bin/mysql' # default 'mysql'
51-
#postgresql: '/usr/bin/pg_restore' # default 'pg_restore'
52-
#sqlite: '/usr/bin/sqlite3' # default 'sqlite3'
35+
# Specify here paths to binaries and options, only if the system can't find
36+
# them by himself.
37+
# Default value depends upon vendor and is documented at
38+
# https://dbtoolsbundle.readthedocs.io/en/stable/configuration.html
39+
#backup_binary: '/usr/bin/pg_dump'
40+
#backup_options: '-Z 5 --lock-wait-timeout=120'
41+
#restore_binary: '/usr/bin/pg_restore'
42+
#restore_options: '-j 2 --clean --if-exists --disable-triggers'
5343

54-
# Default options to pass to the binary when backing up or restoring
55-
# a database. Those options must be defined per connection.
56-
# If you do not define some default options, here or by using the
57-
# "--extra-options" option when invoking the command, the following
58-
# ones will be used according to the database vendor:
59-
# - When backing up:
60-
# - MariaDB: --no-tablespaces
61-
# - MySQL: --no-tablespaces
62-
# - PostgreSQL: -Z 5 --lock-wait-timeout=120
63-
# - SQLite: -bail
64-
# - When restoring:
65-
# - MariaDB: None
66-
# - MySQL: None
67-
# - PostgreSQL: -j 2 --clean --if-exists --disable-triggers
68-
# - SQLite: None
69-
#backupper_options:
70-
#default: ''
71-
#another_connection: ''
72-
#restorer_options:
73-
#default: ''
74-
#another_connection: ''
44+
# You may specify a list of connections with varying configuration on
45+
# a per-connection basis.
46+
# Each key is a doctrine connection name, all values upper are allowed
47+
# for each unique connection.
48+
#connections:
49+
# connection_one:
50+
# backup_expiration_age: '3 month ago'
51+
# # ...
52+
# connection_two:
53+
# backup_options: '-Z 5 --lock-wait-timeout=60'
54+
# restore_options: '-j 3 --clean'
55+
56+
# You can explicitely set which will be default connection in use when
57+
# none providen in the command line options. If you omit this configuration
58+
# value, then the first one in the list will be used.
59+
#default_connection: connection_one
7560

7661
# Update this configuration if you want to look for anonymizers in a custom folder.
7762
# These are default paths that will always be registered even if you override

src/Backupper/AbstractBackupper.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace MakinaCorpus\DbToolsBundle\Backupper;
66

7+
use MakinaCorpus\DbToolsBundle\Configuration\Configuration;
78
use MakinaCorpus\DbToolsBundle\Helper\Output\NullOutput;
89
use MakinaCorpus\DbToolsBundle\Helper\Process\CommandLine;
910
use MakinaCorpus\DbToolsBundle\Helper\Process\ProcessTrait;
@@ -22,21 +23,24 @@ abstract class AbstractBackupper implements LoggerAwareInterface
2223
{
2324
use ProcessTrait;
2425

26+
protected string $binary;
2527
protected ?string $destination = null;
2628
protected string $defaultOptions = '';
2729
protected ?string $extraOptions = null;
2830
protected bool $ignoreDefaultOptions = false;
2931
protected array $excludedTables = [];
3032
protected bool $verbose = false;
31-
protected ?int $timeout = 600;
33+
protected ?int $timeout = null;
3234

3335
public function __construct(
34-
protected string $binary,
35-
protected DatabaseSession $databaseSession,
36-
protected Dsn $databaseDsn,
37-
?string $defaultOptions = null,
36+
protected readonly DatabaseSession $databaseSession,
37+
protected readonly Dsn $databaseDsn,
38+
protected readonly Configuration $config,
3839
) {
39-
$this->defaultOptions = $defaultOptions ?? $this->getBuiltinDefaultOptions();
40+
$this->excludedTables = $config->getBackupExcludedTables();
41+
$this->binary = $config->getBackupBinary() ?? $this->getDefaultBinary();
42+
$this->defaultOptions = $config->getBackupOptions() ?? $this->getBuiltinDefaultOptions();
43+
$this->timeout = $config->getBackupTimeout();
4044

4145
$this->destination = \sprintf(
4246
'%s/db-tools-backup-%s.dump',
@@ -161,6 +165,11 @@ protected function beforeProcess(): void
161165
$this->process->setTimeout(null === $this->timeout ? null : (float) $this->timeout);
162166
}
163167

168+
/**
169+
* Get default binary path and name (e.g. "/usr/bin/foosql-backup").
170+
*/
171+
abstract protected function getDefaultBinary(): string;
172+
164173
/**
165174
* Provide the built-in default options that will be used if none is given
166175
* through the dedicated constructor argument.

0 commit comments

Comments
 (0)