### Replace Example README with Template Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/contribute/pack.md Replace the example README file with the template's example README. This provides a starting structure for your pack's documentation. ```sh rm README.md mv README.md.example README.md ``` -------------------------------- ### Build and Start Docker Stack Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/contribute/guide.md Use these commands to build the Docker images and start the development environment. ```sh # build the docker stack ./dev.sh build # then, start it ./dev.sh up ``` -------------------------------- ### Check DbToolsBundle Installation (Standalone) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/getting-started/installation.md Verify that DbToolsBundle can find the necessary backup and restoration binaries for your database connections in a standalone setup. ```sh vendor/bin/db-tools check ``` -------------------------------- ### Install DbToolsBundle (Standalone) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/getting-started/installation.md Add DbToolsBundle to your PHP project using Composer for standalone installations. Copy the default configuration file to customize connection settings. ```sh composer require makinacorpus/db-tools-bundle ``` ```sh cd your_project_dir cp vendor/makinacorpus/db-tools-bundle/config/db_tools.standalone.sample.yaml db_tools.config.yaml ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/README.md Run these commands in your terminal to build the documentation locally. Ensure Node.js is installed and use the specified version manager. ```sh nvm use npm ci npm run docs:dev ``` -------------------------------- ### Remove Example Files Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/contribute/pack.md Clean up the template by removing example anonymizer files and their corresponding tests. This prepares the pack for your custom anonymizers. ```sh rm src/Anonymizer/MyAnonymizer.php rm tests/Functional/Anonymizer/MyAnonymizerTest.php ``` -------------------------------- ### Adapt README for Your Pack Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/contribute/pack.md Update the `README.md` file with your pack's specific name, description, anonymizer details, and installation command. This ensures accurate documentation for users. ```md # DbToolsBundle - Pack [your pack name] # DbToolsBundle - Awesome pack [a short description] An awesome pack for anonymizing many things! This pack provides: * `my-pack:anonymizer-1`: a short description of this anonymizer * `my-pack:anonymizer-2`: a short description of this anonymizer * `my-pack:anonymizer-3`: a short description of this anonymizer Fill this later ## Installation Run the following command to add this pack to your application: \\ composer require db-tools-bundle/pack-[your pack] composer require my-vendor/pack-awesome \\ Learn more about how to use this package reading [the DbToolsBundle documentation](https://dbtoolsbundle.readthedocs.io/) on Read the Docs. ## Licence This software is published under the [MIT License](./LICENCE.md). ``` -------------------------------- ### Configure Backup/Restore Binaries (Symfony) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md Specify the absolute paths to backup and restore binaries when they are not found in the system's default PATH. This is useful for custom installations. ```yaml db_tools: backup_binary: '/usr/local/bin/pg_dump' restore_binary: '/usr/local/bin/pg_restore' ``` -------------------------------- ### Check DbToolsBundle Installation (Docker) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/getting-started/installation.md Verify that DbToolsBundle can find the necessary backup and restoration binaries for your database connections within a Docker environment. ```sh docker compose run dbtools check ``` -------------------------------- ### Configure IBAN-BIC Anonymizer in Docker Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/iban-bic.md Example configuration for the IBAN-BIC anonymizer within a standalone Docker setup using YAML. ```yaml # db_tools.config.yaml anonymization: default: customer: iban: # An arbitrary key target: table anonymizer: iban-bic options: iban: 'account_iban' bic: 'account_bic' #... ``` -------------------------------- ### Install DbToolsBundle (Symfony) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/getting-started/installation.md Add DbToolsBundle to your Symfony project using Composer and activate it in config/bundles.php. Copy the default configuration file for bundle-specific settings. ```sh composer require makinacorpus/db-tools-bundle ``` ```php // config/bundles.php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], //... Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], // ... MakinaCorpus\DbToolsBundle\Bridge\Symfony\DbToolsBundle::class => ['all' => true], // [!code ++] ]; ``` ```sh cd your_project_dir cp vendor/makinacorpus/db-tools-bundle/config/packages/db_tools.yaml config/packages/ ``` -------------------------------- ### Configure MD5 Anonymizer in YAML Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/md5.md Example of configuring the MD5 anonymizer for a specific column in the `db_tools.config.yaml` file. ```yaml # db_tools.config.yaml anonymization: default: customer: my_dirty_secret: md5 #... ``` -------------------------------- ### Backup Production Data Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/workflow.md Initiates a backup of production data. Choose the command based on your environment setup (standalone, Symfony CLI, or Docker Compose). ```bash vendor/bin/db-tools backup ``` ```bash php bin/console db-tools:backup ``` ```bash docker compose run dbtools backup ``` -------------------------------- ### Get Global Database Statistics Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/stats.md Run the stats command without arguments to get global database statistics. Output may vary depending on the database driver. ```sh vendor/bin/db-tools stats ``` ```sh php bin/console db-tools:stats ``` ```sh docker compose run dbtools stats ``` -------------------------------- ### Run DBToolsBundle Stats (Standalone) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/getting-started/basics.md Execute the DBToolsBundle stats command directly using the vendor binary. This is useful for projects with Composer installed. ```sh vendor/bin/db-tools stats ``` -------------------------------- ### Check DbToolsBundle Installation (Symfony) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/getting-started/installation.md Verify that DbToolsBundle can find the necessary backup and restoration binaries for your database connections using Symfony Console commands. ```sh php bin/console db-tools:check ``` -------------------------------- ### Install DbToolsBundle with Composer Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/README.md Install the DbToolsBundle package into your PHP application using Composer. This command requires PHP 8.1 or higher. ```sh composer require makinacorpus/db-tools-bundle ``` -------------------------------- ### Configure MD5 Anonymizer with PHP Attributes Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/md5.md Example of using PHP attributes to configure the MD5 anonymizer for an entity property. ```php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use MakinaCorpus\DbToolsBundle\Attribute\Anonymize; #[ORM\Entity()] #[ORM\Table(name: 'customer')] class Customer { // ... #[ORM\Column(length: 255)] #[Anonymize(type: 'md5')] // [!code ++] private ?string $myDirtySecret = null; // ... } ``` -------------------------------- ### Get Index Statistics (PostgreSQL Only) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/stats.md Retrieve index statistics for PostgreSQL databases, including size and performance-related values. Output is ordered by index size in descending order. ```sh vendor/bin/db-tools stats index ``` ```sh php bin/console db-tools:stats index ``` ```sh docker compose run dbtools stats index ``` -------------------------------- ### Anonymize Backup File (Standalone) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/command.md Run the anonymization command using the standalone script. This is typically used when DBToolsBundle is installed as a Composer dependency. ```sh vendor/bin/db-tools anonymize path/to/your/backup/to/anonymized ``` -------------------------------- ### Anonymize Backup File (Docker Compose) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/command.md Use Docker Compose to run the anonymization command. This is ideal for containerized environments where DBToolsBundle is part of a Docker setup. ```sh docker compose run dbtools anonymize path/to/your/backup/to/anonymized ``` -------------------------------- ### Configure Pattern Anonymizer with Attributes in PHP Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/pattern.md Configure the pattern anonymizer using PHP attributes for entity fields. This example demonstrates setting a customer biography pattern directly on the entity class. ```php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use MakinaCorpus\DbToolsBundle\Attribute\Anonymize; #[ORM\Entity()] #[ORM\Table(name: 'customer')] class Customer { // ... #[ORM\Column] #[Anonymize(type: 'pattern', options: ['value' => '{firstname} {lastname} lives in {address:locality} in {address:country}, he has [2,7] cats.'])] // [!code ++] private ?string $biography = null; } ``` -------------------------------- ### Display dev.sh Help Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/contribute/guide.md Launch the `dev.sh` script without arguments to display its help information and learn more about its capabilities. ```sh ./dev.sh ``` -------------------------------- ### Configure Backup/Restore Binaries (Standalone/Docker) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md Specify the absolute paths to backup and restore binaries for standalone or Docker environments when they are not found in the system's default PATH. ```yaml backup_binary: '/usr/local/bin/pg_dump' restore_binary: '/usr/local/bin/pg_restore' ``` -------------------------------- ### Configure Multiple Connections (Standalone/Docker) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md Define backup and restore binary paths on a per-connection basis for standalone or Docker environments when managing multiple database connections. ```yaml connections: connection_one: backup_binary: '/usr/local/bin/pg_dump' restore_binary: '/usr/local/bin/pg_restore' connection_two: backup_binary: '/usr/local/bin/mysqldump' restore_binary: '/usr/local/bin/mysql' ``` -------------------------------- ### Configure Default Backup Options (Standalone/Docker) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md Set default command-line options for backup operations across all connections or for specific connections in standalone or Docker environments. ```yaml backup_options: '--an-option' restore_options: '--a-first-one --a-second-one' ``` ```yaml connections: connection_one: backup_options: '--an-option' restore_options: '-xyz --another' connection_two: backup_options: '--a-first-one --a-second-one' restore_options: '-O sample-value' ``` -------------------------------- ### Install fr-FR Anonymizer Pack Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/packs.md Install the official French (fr-FR) anonymizer pack using Composer. This pack provides locale-specific anonymizers for addresses, first names, last names, and phone numbers. ```sh composer require db-tools-bundle/pack-fr-fr ``` -------------------------------- ### Configure IBAN-BIC Anonymizer with Attributes Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/iban-bic.md Example of configuring the IBAN-BIC anonymizer using PHP attributes in a Symfony entity. ```php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use MakinaCorpus\DbToolsBundle\Attribute\Anonymize; #[ORM\Entity()] #[ORM\Table(name: 'customer')] #[Anonymize(type: 'iban-bic', options: [ 'iban' => 'account_iban', 'bic' => 'account_bic' ])] // [!code ++] class Customer { // ... #[ORM\Column(length: 255)] private ?string $accountIban = null; #[ORM\Column(length: 255)] private ?string $accountBic = null; // ... } ``` -------------------------------- ### Configure Restore Command Options Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/reference.md Allows adding custom command-line options to the database restore command. Default options are provided for PostgreSQL if none are specified here or via the command line. ```yaml db_tools: restore_options: '-j 2 --clean --if-exists --disable-triggers' ``` ```yaml restore_options: '-j 2 --clean --if-exists --disable-triggers' ``` -------------------------------- ### Configure MD5 Anonymizer in YAML (Symfony) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/md5.md Example of configuring the MD5 anonymizer for a specific entity in Symfony's `config/anonymization.yaml`. ```yaml # config/anonymization.yaml customer: my_dirty_secret: md5 #... ``` -------------------------------- ### Configure Default Backup Options (Symfony) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md Set default command-line options for backup operations across all connections or for specific connections. ```yaml db_tools: backup_options: '--an-option' restore_options: '--a-first-one --a-second-one' ``` ```yaml db_tools: connections: connection_one: backup_options: '--an-option' restore_options: '-xyz --another' connection_two: backup_options: '--a-first-one --a-second-one' restore_options: '-O sample-value' ``` -------------------------------- ### Ignore Default Options (Standalone) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/backup_restore.md Run a restoration without default options in a standalone environment. ```sh # Will run a restoration without any special options except essential ones: vendor/bin/db-tools restore --ignore-default-options ``` -------------------------------- ### Configure IBAN-BIC Anonymizer in Symfony YAML Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/iban-bic.md Example configuration for the IBAN-BIC anonymizer in a Symfony application using YAML files. ```yaml # config/anonymization.yaml customer: iban: # An arbitrary key target: table anonymizer: iban-bic options: iban: 'account_iban' bic: 'account_bic' #... ``` -------------------------------- ### Date Anonymization Configuration (YAML) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/date.md Provides a complete YAML configuration for anonymizing date fields, including examples for delta-based and range-based anonymization. ```yaml # config/anonymization.yaml customer: # Will add to the existing date a random interval in the [-delta, +delta] interval. birthDate: anonymizer: date options: {delta: '1 month 15 day'} customer: # Will pick a random date in the given [min, max] interval. lastLogin: anonymizer: date options: {min: 'now -3 month', max: 'now'} customer: # And example with absolute dates. createdAt: anonymizer: date options: {min: '1789-05-05', max: '2024-03-15', format: 'date'} #... ``` -------------------------------- ### Backup Database (Docker) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/getting-started/basics.md Run this command in a Dockerized environment to back up your database with DbToolsBundle. ```sh docker compose run dbtools backup ``` -------------------------------- ### List Available Backups Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/workflow.md Lists existing backup files. Use this to identify the backup you wish to anonymize. Select the command corresponding to your environment. ```bash vendor/bin/db-tools restore --list ``` ```bash php bin/console db-tools:restore --list ``` ```bash docker compose run dbtools restore --list ``` -------------------------------- ### Configure Multiple Connections (Symfony) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md Define backup and restore binary paths on a per-connection basis when managing multiple database connections with different binary requirements. ```yaml db_tools: connections: connection_one: backup_binary: '/usr/local/bin/pg_dump' restore_binary: '/usr/local/bin/pg_restore' connection_two: backup_binary: '/usr/local/bin/mysqldump' restore_binary: '/usr/local/bin/mysql' ``` -------------------------------- ### Pass Extra Options (Standalone) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/backup_restore.md Pass custom options to the restoration binary in a standalone environment. ```sh vendor/bin/db-tools restore --extra-options "--opt1 val1 --opt2 val2 --flag" ``` -------------------------------- ### Backup Database from Specific Connection Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/backup_restore.md Specify a database connection to back up using the --connection option. ```sh vendor/bin/db-tools backup --connection other_connection_name ``` ```sh php bin/console db-tools:backup --connection other_connection_name ``` ```sh docker compose run dbtools --connection other_connection_name ``` -------------------------------- ### Restore Anonymized Backup Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/workflow.md Restores the anonymized data to your local environment. Specify the path to the anonymized backup file. The command depends on your setup. ```bash vendor/bin/db-tools restore --filename path/to/your/anonymized/backup ``` ```bash php bin/console db-tools:restore --filename path/to/your/anonymized/backup ``` ```bash docker compose run dbtools restore --filename path/to/your/anonymized/backup ``` -------------------------------- ### Show All Table Statistics Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/stats.md Display all available statistics for tables, including info and read tags. Use the `--all` or `-a` switch to show all values. ```sh vendor/bin/db-tools stats table -a ``` ```sh php bin/console db-tools:stats table -a ``` ```sh docker compose run dbtools stats table -a ``` -------------------------------- ### Connection Specific Options (Standalone Docker) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/reference.md Define detailed connection configurations for standalone Docker, including URL, backup/restore parameters, and storage details. Supports multiple connection definitions. ```yaml # With connection specific options. connections: connection_one: # Connection URL for connecting. # Please refer to makinacorpus/db-query-builder or documentation for more information. # Any URL built for doctrine/dbal usage should work. # URL is the sole mandatory parameter. # Complete list of accepted parameters follows. url: "pgsql://username:password@hostname:port/database?version=16.0&other_option=..." backup_binary: /usr/local/bin/vendor-one-dump backup_excluded_tables: ['table_one', 'table_two'] backup_expiration_age: '1 month ago' backup_options: --no-table-lock backup_timeout: 2000 restore_binary: /usr/local/bin/vendor-one-restore restore_options: --disable-triggers --other-option restore_timeout: 5000 storage_directory: /path/to/storage storage_filename_strategy: datetime connection_two: #... # With all default options, only database DSN. connections: connection_two: "mysql://username:password@hostname:port/database?version=8.1&other_option=..." connection_two: #... # With a single connection. # Connection name will be "default". connections: "pgsql://username:password@hostname:port/database?version=16.0&other_option=..." ``` -------------------------------- ### Ignore Default Backup Options Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/backup_restore.md Run a backup command ignoring any default options configured for the binary by using the --ignore-default-options flag. ```sh # Will run a backup without any special options except essential ones: vendor/bin/db-tools backup --ignore-default-options ``` ```sh # Will run a backup without any special options except essential ones: php bin/console db-tools:backup --ignore-default-options ``` ```sh # Will run a backup without any special options except essential ones: docker compose run dbtools backup --ignore-default-options ``` -------------------------------- ### Configure Pattern Anonymizer in YAML Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/pattern.md Configure the pattern anonymizer in a YAML configuration file for your application. This example shows how to set a default customer biography pattern. ```yaml # db_tools.config.yaml anonymization: default: customer: biography: anonymizer: pattern options: {value: '{firstname} {lastname} lives in {address:locality} in {address:country}, he has [2,7] cats.'} #... ``` -------------------------------- ### Docker Compose for Database and DbToolsBundle Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/index.md Set up a Docker Compose configuration to run PostgreSQL and the DbToolsBundle Docker image. This is useful for CI/CD environments. ```yaml services: postgres: environment: POSTGRES_PASSWORD: password POSTGRES_DB: db POSTGRES_USER: db ports: - 5439:5432 networks: - site dbtools: // [!code ++] image: makinacorpus/dbtoolsbundle:stable // [!code ++] networks: // [!code ++] - site // [!code ++] volumes: // [!code ++] - ./db_tools.config.yaml:/var/www/db_tools.config.yaml // [!code ++] networks: site: ``` -------------------------------- ### Restore from Specific Filename (Standalone) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/backup_restore.md Restore a database from a specified backup file in a standalone environment. ```sh vendor/bin/db-tools restore --filename /path/to/my/backup.sql ``` -------------------------------- ### Configure Backup Excluded Tables (Standalone Docker - Per Connection) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md Set excluded tables for backups on a per-connection basis in standalone Docker. ```yaml connections: connection_one: backup_excluded_tables: ['table1', 'table2'] connection_two: backup_excluded_tables: ['table3', 'table4'] ``` -------------------------------- ### Get Detailed Table Statistics Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/stats.md Retrieve detailed statistics for tables, including size, row count, and maintenance information. Output is ordered by table size in descending order. ```sh vendor/bin/db-tools stats table ``` ```sh php bin/console db-tools:stats table ``` ```sh docker compose run dbtools stats table ``` -------------------------------- ### Configure Pattern Anonymizer in YAML (Symfony) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/pattern.md Configure the pattern anonymizer within a Symfony application's anonymization configuration file. This example sets the pattern for a customer's biography. ```yaml # config/anonymization.yaml customer: biography: anonymizer: pattern options: {value: '{firstname} {lastname} lives in {address:locality} in {address:country}, he has [2,7] cats.'} #... ``` -------------------------------- ### Restore Database (Docker) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/getting-started/basics.md Run this command in a Dockerized environment to restore your database from a backup. It will list available backups for selection. ```sh docker compose run dbtools restore ``` -------------------------------- ### Backup Timeout Configuration (Standalone Docker) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/reference.md Configure the backup process timeout in seconds for standalone Docker environments. Accepts date interval strings or integers. ```yaml backup_timeout: '2 minutes and 7 seconds' ``` ```yaml backup_timeout: 67 ``` -------------------------------- ### Configure Multicolumn Address Anonymizer in Docker Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/essentials.md Configure the AddressAnonymizer for multiple columns in a Docker environment using YAML. This setup maps logical anonymization fields to physical table columns. ```yaml # db_tools.config.yaml anonymization: default: customer: address: target: table anonymizer: address options: street_address: 'street' secondary_address: 'street_address_2' postal_code: 'zip_code' locality: 'city' region: 'region' country: 'country' #... ``` -------------------------------- ### Configure Password Anonymizer in Docker Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/password.md Configure the password anonymizer in your Docker setup using YAML. You can set a default password or specify options like the hashing algorithm and a custom password. ```yaml # db_tools.config.yaml anonymization: default: customer: password: password # Or, with options: customer: password: anonymizer: password options: {algorithm: 'sodium', password: '123456789'} #... ``` -------------------------------- ### Set Global Backup and Restore Timeouts (Standalone Docker) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md Configure global backup and restore timeouts in `db_tools.config.yaml`. Values can be date interval strings or seconds. Note that duplicate keys will result in the last value being used. ```yaml # As a date interval string. backup_timeout: '6 minutes 30 seconds' restore_timeout: '3 minutes 15 seconds' # As a number of seconds integer value. backup_timeout: 390 restore_timeout: 195 ``` -------------------------------- ### Set Custom Backup Options (Standalone Docker) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/reference.md Define custom command line options for the backup command in a standalone Docker environment. This overrides default options. ```yaml backup_options: '-Z 5 --lock-wait-timeout=120' ``` -------------------------------- ### Anonymization Configuration in Symfony Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/reference.md Configure anonymization settings within a Symfony project. Use the `db_tools` top-level key to avoid conflicts with other bundles. This example shows configuration for multiple database connections. ```yaml db_tools: anonymization: connection_one: table1: column1: anonymizer: anonymizer_name # ... anonymizer specific options... column2: # ... table2: # ... connection_two: # ... ``` -------------------------------- ### Configure Backup Binary Path in Symfony Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/reference.md Set the filesystem path for the backup command in a Symfony environment. Defaults to common executable names. ```yaml db_tools: backup_binary: /usr/bin/pg_dump ``` -------------------------------- ### Restore from Specific Connection (Standalone) Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/backup_restore.md Restore a database from a specific connection in a standalone environment. ```sh vendor/bin/db-tools restore --connection other_connection_name ``` -------------------------------- ### Configure Constant Anonymizer in Docker Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/constant.md Configure the constant anonymizer in your Docker setup using the db_tools.config.yaml file. Specify the type as 'constant' and provide the desired value and optionally its SQL type in the options. ```yaml # db_tools.config.yaml anonymization: default: customer: address: sensible_content: type: constant options: {value: '_______'} # or for example customer: address: sensible_content: type: constant options: {value: '2012-12-21', type: 'date'} #... ``` -------------------------------- ### PHP Attribute Configuration for Lorem Ipsum Anonymizer Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/core-anonymizers/lorem-ipsum.md Use PHP attributes to configure the Lorem Ipsum anonymizer directly within your entity classes. Examples show default, multiple paragraphs with HTML, and a specific word count. ```php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use MakinaCorpus\DbToolsBundle\Attribute\Anonymize; #[ORM\Entity()] #[ORM\Table(name: 'customer')] class Customer { // ... #[ORM\Column(length: 255)] #[Anonymize('lorem')] // [!code ++] private ?string $message = null; #[ORM\Column(length: 255)] // Will generate 10 paragraphs, each one surrounded by a html `
` tag
#[Anonymize('lorem', ['paragraphs' => 10, 'html' => true])] // [!code ++]
private ?string $message = null;
#[ORM\Column(length: 255)]
// Will only generate 5 words
#[Anonymize('lorem', ['words' => 5])] // [!code ++]
private ?string $message = null;
// ...
}
```
--------------------------------
### Set Connection-Specific Backup and Restore Timeouts (Standalone Docker)
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md
Define different backup and restore timeouts for individual connections in `db_tools.config.yaml`. Values can be date interval strings or seconds.
```yaml
connections:
connection_one:
backup_timeout: '6 minutes 30 seconds'
restore_timeout: '3 minutes 15 seconds'
connection_two:
backup_timeout: 390
restore_timeout: 195
```
--------------------------------
### Configure Backup Binary Path in Standalone Docker
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/reference.md
Specify the backup binary path in a standalone Docker configuration. This can be overridden per connection if needed.
```yaml
backup_binary: /usr/bin/pg_dump
```
--------------------------------
### Connection Specific Options (Symfony)
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/reference.md
Configure specific backup and restore parameters for a database connection within a Symfony application. Includes binary paths, timeouts, and storage settings.
```yaml
db_tools:
connections:
connection_one:
backup_binary: /usr/local/bin/vendor-one-dump
backup_excluded_tables: ['table_one', 'table_two']
backup_expiration_age: '1 month ago'
backup_options: --no-table-lock
backup_timeout: 2000
restore_binary: /usr/local/bin/vendor-one-restore
restore_options: --disable-triggers --other-option
restore_timeout: 5000
storage_directory: /path/to/storage
storage_filename_strategy: datetime
```
--------------------------------
### Specify Restore Binary Path
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/reference.md
Sets the filesystem path to the database restore command. Defaults are usually executable names that work on most Linux distributions.
```yaml
db_tools:
restore_binary: /usr/bin/pg_restore
```
```yaml
restore_binary: /usr/bin/pg_restore
```
--------------------------------
### Pass Extra Options (Docker)
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/backup_restore.md
Pass custom options to the restoration binary using Docker Compose.
```sh
docker compose run dbtools restore --extra-options "--opt1 val1 --opt2 val2 --flag"
```
--------------------------------
### Skip Backup Cleanup
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/backup_restore.md
Launch the backup command without the cleanup step using the --no-cleanup option. Note that this will prevent automatic removal of obsolete backup files.
```sh
vendor/bin/db-tools backup --no-cleanup
```
```sh
php bin/console db-tools:backup --no-cleanup
```
```sh
docker compose run dbtools backup --no-cleanup
```
--------------------------------
### Configure Backup Excluded Tables (Standalone Docker - Global)
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md
Set globally excluded tables for backups in the standalone Docker configuration file.
```yaml
backup_excluded_tables: ['table1', 'table2']
```
--------------------------------
### Pass Extra Options to Backup Binary
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/backup_restore.md
Provide custom options to the backup binary using the --extra-options or -o option. These options are appended to default options unless --ignore-default-options is used.
```sh
vendor/bin/db-tools backup --extra-options "--opt1 val1 --opt2 val2 --flag"
```
```sh
php bin/console db-tools:backup --extra-options "--opt1 val1 --opt2 val2 --flag"
```
```sh
docker compose run dbtools backup --extra-options "--opt1 val1 --opt2 val2 --flag"
```
--------------------------------
### Set Custom Backup Options (Symfony)
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/reference.md
Define custom command line options for the backup command in a Symfony environment. This overrides default options.
```yaml
db_tools:
backup_options: '-Z 5 --lock-wait-timeout=120'
```
--------------------------------
### List Available Anonymizers (Standalone)
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/essentials.md
Lists all available anonymizers using the DbToolsBundle CLI in a standalone environment.
```bash
vendor/bin/db-tools anonymization:list
```
--------------------------------
### Backup Database (Standalone)
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/getting-started/basics.md
Use this command to back up your database when using DbToolsBundle as a standalone tool.
```sh
vendor/bin/db-tools backup
```
--------------------------------
### Configure DbToolsBundle with Docker Compose
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/getting-started/installation.md
Integrate the DbToolsBundle Docker image into your docker-compose stack. Copy the default configuration file from the container and update connection strings.
```yaml
version: '3.8'
services:
postgres:
image: postgres:15
environment:
POSTGRES_PASSWORD: password
POSTGRES_DB: db
POSTGRES_USER: db
ports:
- 5439:5432
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- site
dbtools: // [!code ++]
image: makinacorpus/dbtoolsbundle:stable // [!code ++]
networks: // [!code ++]
- site // [!code ++]
volumes: // [!code ++]
- ./db_tools.config.yaml:/var/www/db_tools.config.yaml // [!code ++]
- ./db_tools:/var/www/var/db_tools // [!code ++]
networks:
site:
volumes:
pgdata:
```
```sh
cd your_project_dir
docker compose cp dbtoolsbundle:/var/www/vendor/makinacorpus/db-tools-bundle/config/db_tools.standalone.sample.yaml db_tools.config.yaml
```
--------------------------------
### Set Global Backup and Restore Timeouts (Symfony)
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md
Configure global backup and restore timeouts in `config/packages/db_tools.yaml`. Values can be date interval strings or seconds. Note that duplicate keys will result in the last value being used.
```yaml
db_tools:
# As a date interval string.
backup_timeout: '6 minutes 30 seconds'
restore_timeout: '3 minutes 15 seconds'
# As a number of seconds integer value.
backup_timeout: 390
restore_timeout: 195
```
--------------------------------
### Check Database Binaries
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md
Verify if DbToolsBundle can find the necessary database binaries for your connections. This command helps diagnose issues with binary paths.
```sh
php bin/console db-tools:check
```
```sh
php vendor/bin/db-tools database:check
```
```sh
docker compose run dbtools database:check
```
--------------------------------
### Set Connection-Specific Backup and Restore Timeouts (Symfony)
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/configuration/basics.md
Define different backup and restore timeouts for individual connections in `config/packages/db_tools.yaml`. Values can be date interval strings or seconds.
```yaml
db_tools:
connections:
connection_one:
backup_timeout: '6 minutes 30 seconds'
restore_timeout: '3 minutes 15 seconds'
connection_two:
backup_timeout: 390
restore_timeout: 195
```
--------------------------------
### Multicolumn Anonymizer Implementation
Source: https://github.com/makinacorpus/dbtoolsbundle/blob/main/docs/content/anonymization/custom-anonymizers.md
Create an anonymizer for multiple columns using a sample by extending AbstractMultipleColumnAnonymizer. Define column names with getColumnNames and provide the sample data with getSample.
```php
namespace App\Anonymizer;
use MakinaCorpus\DbToolsBundle\Anonymization\Anonymizer\AbstractMultipleColumnAnonymizer;
use MakinaCorpus\DbToolsBundle\Attribute\AsAnonymizer;
#[AsAnonymizer(
name: 'my_multicolumn_anonymizer',
pack: 'my_app',
description: <<