Skip to content

Commit

Permalink
Doc - update index and backup_restore & stats with flavors
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMellerin committed Nov 15, 2024
1 parent 7fb939a commit 571e3f2
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 8 deletions.
156 changes: 153 additions & 3 deletions docs/content/backup_restore.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Backup and Restore

The *DbToolsBundle* comes with two Symfony Console commands to back up and restore
*DbToolsBundle* comes with two commands to back up and restore
your database but also a tiny backups manager which handle backup files for you.

## Backup command
Expand All @@ -15,14 +15,39 @@ With time, this directory will grow, that's why a [backup expiration age](./conf
was added. Every time you launch the command, at the end, it will be asked if you want to remove obsolete
backup files (i.e. files that have passed their expiration date).

<div class="standalone">

```sh
vendor/bin/db-tools backup
```

</div>
<div class="symfony">

```sh
console db-tools:backup
```

</div>

You can specify the behavior of the command with some options detailed below.

### Connection

<div class="standalone">

By default, the command will backup the database from the default connection.

If you configured several ones, you can choose to back up a database from a specific
connection with `--connection` option:

```sh
vendor/bin/db-tools backup --connection other_connection_name
```

</div>
<div class="symfony">

By default, the command will backup the database from the default DBAL connection.

You can choose to back up a database from another connection with `--connection` option:
Expand All @@ -31,13 +56,28 @@ You can choose to back up a database from another connection with `--connection`
console db-tools:backup --connection other_connection_name
```

</div>

### Excluded tables

You may have configured [tables to be exclude in the bundle configuration](./configuration#excluded-tables).
If so, these tables will be automatically excluded each time you launch the command.

But if you want to temporarily exclude some tables, run the command with the `--excluded-table` option:

<div class="standalone">

```sh
# Exclude a table
vendor/bin/db-tools backup --excluded-table table_to_exclude

# Or more
vendor/bin/db-tools backup --excluded-table table_to_exclude_1 --excluded-table table_to_exclude_2
```

</div>
<div class="symfony">

```sh
# Exclude a table
console db-tools:backup --excluded-table table_to_exclude
Expand All @@ -46,14 +86,27 @@ console db-tools:backup --excluded-table table_to_exclude
console db-tools:backup --excluded-table table_to_exclude_1 --excluded-table table_to_exclude_2
```

</div>

### No cleanup

If you want to skip the cleanup step, launch it with option `--no-cleanup':

<div class="standalone">

```sh
vendor/bin/db-tools backup --no-cleanup
```

</div>
<div class="symfony">

```sh
console db-tools:backup --no-cleanup
```

</div>

:::warning
Note that using this option, backup files will never be cleaned up.
:::
Expand All @@ -63,10 +116,21 @@ Note that using this option, backup files will never be cleaned up.
If you need to occasionally provide some custom options to the backup binary,
use the `--extra-options` (`-o`) option in your command:

<div class="standalone">

```sh
vendor/bin/db-tools backup --extra-options "--opt1 val1 --opt2 val2 --flag"
```

</div>
<div class="symfony">

```sh
console db-tools:backup --extra-options "--opt1 val1 --opt2 val2 --flag"
```

</div>

Unless you specify the `--ignore-default-options` option, the custom options
will be added to the [default options](./configuration#default-binary-options).

Expand All @@ -75,24 +139,61 @@ will be added to the [default options](./configuration#default-binary-options).
If necessary, [default options](./configuration#default-binary-options) can be
ignored for a backup by using the `--ignore-default-options` option:

<div class="standalone">

```sh
# Will run a backup without any special options except essential ones:
vendor/bin/db-tools backup --ignore-default-options
```

</div>
<div class="symfony">

```sh
# Will run a backup without any special options except essential ones:
console db-tools:backup --ignore-default-options
```

</div>

## Restore command

The restore command will use [predefined or configured binary](./configuration#binaries) for your database vendor with correct parameters
to restore your database from an existing backup files.

<div class="standalone">

```sh
vendor/bin/db-tools restore
```

</div>
<div class="symfony">

```sh
console db-tools:restore
```

</div>

You can specify the behavior of the command with some options detailed below.

### Connection

<div class="standalone">

By default, the command will restore the database from the default connection.

If you configured several ones, you can choose to restore a database from a specific
connection with `--connection` option:

```sh
vendor/bin/db-tools restore --connection other_connection_name
```

</div>
<div class="symfony">

By default, the command will restore the database from the default DBAL connection.

You can choose to restore a database from another connection with `--connection` option:
Expand All @@ -101,6 +202,8 @@ You can choose to restore a database from another connection with `--connection`
console db-tools:restore --connection other_connection_name
```

</div>

### Filename

When you launch this command, existing backup files will be listed and it
Expand All @@ -109,19 +212,42 @@ will be asked you to choose the one to restore.
If you want to skip this step, or if your backup file is unknown to the storage
manager, you can specify a file to restore with the `--filename` option:

<div class="standalone">

```sh
vendor/bin/db-tools restore --filename /path/to/my/backup.sql
```

</div>
<div class="symfony">

```sh
console db-tools:restore --filename /path/to/my/backup.sql
```

</div>

### Force

Each time you run this command, as it is a sensitive operation, a confirmation will
be asked. If you want to skip it, use the `--force` option.


<div class="standalone">

```sh
vendor/bin/db-tools restore --force
```

</div>
<div class="symfony">

```sh
console db-tools:restore --force
```

</div>

:::danger
By default, this command does not allow to restore a database when used in **production environment**.
Even if you use it with `--force`.
Expand All @@ -138,10 +264,21 @@ really want to do so.
If you need to occasionally provide some custom options to the restoration
binary, use the `--extra-options` (`-o`) option in your command:

<div class="standalone">

```sh
vendor/bin/db-tools restore --extra-options "--opt1 val1 --opt2 val2 --flag"
```

</div>
<div class="symfony">

```sh
console db-tools:restore --extra-options "--opt1 val1 --opt2 val2 --flag"
```

</div>

Unless you specify the `--ignore-default-options` option, the custom options
will be added to the [default options](./configuration#default-binary-options).

Expand All @@ -150,23 +287,36 @@ will be added to the [default options](./configuration#default-binary-options).
If necessary, [default options](./configuration#default-binary-options) can be
ignored for a restoration by using the `--ignore-default-options` option:

<div class="standalone">

```sh
# Will run a restoration without any special options except essential ones:
vendor/bin/db-tools restore --ignore-default-options
```

</div>
<div class="symfony">

```sh
# Will run a restoration without any special options except essential ones:
console db-tools:restore --ignore-default-options
```

</div>


## Storage

As mentioned earlier on this page, the *DbToolsBundle* can list existing backup files
when you want to restore a previous one with the restore command.

All backups are stored in a directory. By default this directory is `%kernel.project_dir%/var/db_tools`
All backups are stored in a directory. By default this directory is <span class="standalone">`your_project_path/db_tools`</span><span class="symfony">`%kernel.project_dir%/var/db_tools`</span>
but [you can choose the directory you want](./configuration#storage-directory).

In this directory, each backup is put in sub-directories depending on the backup date. The backup's filename
is generated from the backup date and the DBAL connection name of the database.

For a backup made the 2023-05-15 at 12:22:35 for the default connection, the filename will be :
`%kernel.project_dir%/var/db_tools/2023/05/default-20230515122235.sql`.
<span class="standalone">`your_project_path/db_tools/2023/05/default-20230515122235.sql``</span><span class="symfony">``%kernel.project_dir%/var/db_tools/2023/05/default-20230515122235.sql``</span>.

Note that the file extension may vary depending on the database vendor.
Loading

0 comments on commit 571e3f2

Please sign in to comment.