-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor label command mechanism to be more flexible * Run all steps wrapped in labeled commands * Rename methods to be in line with lifecycle * Deprecate exec-pre and exec-post labels * Add documentation * Use type alias for lifecycle phases * Fix bad imports * Fix command lookup for deprecated labels * Use more generic naming for lifecycle phase * Fail on erroneous post command * Update documentation
- Loading branch information
Showing
5 changed files
with
128 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,14 +20,15 @@ It handles __recurring or one-off backups of Docker volumes__ to a __local direc | |
- [Automatically pruning old backups](#automatically-pruning-old-backups) | ||
- [Send email notifications on failed backup runs](#send-email-notifications-on-failed-backup-runs) | ||
- [Customize notifications](#customize-notifications) | ||
- [Run custom commands before / after backup](#run-custom-commands-before--after-backup) | ||
- [Run custom commands during the backup lifecycle](#run-custom-commands-during-the-backup-lifecycle) | ||
- [Encrypting your backup using GPG](#encrypting-your-backup-using-gpg) | ||
- [Restoring a volume from a backup](#restoring-a-volume-from-a-backup) | ||
- [Set the timezone the container runs in](#set-the-timezone-the-container-runs-in) | ||
- [Using with Docker Swarm](#using-with-docker-swarm) | ||
- [Manually triggering a backup](#manually-triggering-a-backup) | ||
- [Update deprecated email configuration](#update-deprecated-email-configuration) | ||
- [Replace deprecated `BACKUP_FROM_SNAPSHOT` usage](#replace-deprecated-backup_from_snapshot-usage) | ||
- [Replace deprecated `exec-pre` and `exec-post` labels](#replace-deprecated-exec-pre-and-exec-post-labels) | ||
- [Using a custom Docker host](#using-a-custom-docker-host) | ||
- [Run multiple backup schedules in the same container](#run-multiple-backup-schedules-in-the-same-container) | ||
- [Define different retention schedules](#define-different-retention-schedules) | ||
|
@@ -351,7 +352,7 @@ You can populate below template according to your requirements and use it as you | |
|
||
# It is possible to define commands to be run in any container before and after | ||
# a backup is conducted. The commands themselves are defined in labels like | ||
# `docker-volume-backup.exec-pre=/bin/sh -c 'mysqldump [options] > dump.sql'. | ||
# `docker-volume-backup.archive-pre=/bin/sh -c 'mysqldump [options] > dump.sql'. | ||
# Several options exist for controlling this feature: | ||
|
||
# By default, any output of such a command is suppressed. If this value | ||
|
@@ -543,11 +544,16 @@ Overridable template names are: `title_success`, `body_success`, `title_failure` | |
|
||
For a full list of available variables and functions, see [this page](https://github.com/offen/docker-volume-backup/blob/master/docs/NOTIFICATION-TEMPLATES.md). | ||
|
||
### Run custom commands before / after backup | ||
### Run custom commands during the backup lifecycle | ||
|
||
In certain scenarios it can be required to run specific commands before and after a backup is taken (e.g. dumping a database). | ||
When mounting the Docker socket into the `docker-volume-backup` container, you can define pre- and post-commands that will be run in the context of the target container. | ||
Such commands are defined by specifying the command in a `docker-volume-backup.exec-[pre|post]` label. | ||
When mounting the Docker socket into the `docker-volume-backup` container, you can define pre- and post-commands that will be run in the context of the target container (it is also possible to run commands inside the `docker-volume-backup` container itself using this feature). | ||
Such commands are defined by specifying the command in a `docker-volume-backup.[step]-[pre|post]` label where `step` can be any of the following phases of a backup lifecyle: | ||
|
||
- `archive` (the tar archive is created) | ||
- `process` (the tar archive is processed, e.g. encrypted - optional) | ||
- `copy` (the tar archive is copied to all configured storages) | ||
- `prune` (existing backups are pruned based on the defined ruleset - optional) | ||
|
||
Taking a database dump using `mysqldump` would look like this: | ||
|
||
|
@@ -561,7 +567,7 @@ services: | |
volumes: | ||
- backup_data:/tmp/backups | ||
labels: | ||
- docker-volume-backup.exec-pre=/bin/sh -c 'mysqldump --all-databases > /backups/dump.sql' | ||
- docker-volume-backup.archive-pre=/bin/sh -c 'mysqldump --all-databases > /backups/dump.sql' | ||
|
||
volumes: | ||
backup_data: | ||
|
@@ -581,7 +587,7 @@ services: | |
volumes: | ||
- backup_data:/tmp/backups | ||
labels: | ||
- docker-volume-backup.exec-pre=/bin/sh -c 'mysqldump --all-databases > /tmp/volume/dump.sql' | ||
- docker-volume-backup.archive-pre=/bin/sh -c 'mysqldump --all-databases > /tmp/volume/dump.sql' | ||
- docker-volume-backup.exec-label=database | ||
backup: | ||
|
@@ -597,7 +603,7 @@ volumes: | |
``` | ||
|
||
|
||
The backup procedure is guaranteed to wait for all `pre` commands to finish. | ||
The backup procedure is guaranteed to wait for all `pre` or `post` commands to finish before proceeding. | ||
However there are no guarantees about the order in which they are run, which could also happen concurrently. | ||
|
||
### Encrypting your backup using GPG | ||
|
@@ -723,7 +729,7 @@ NOTIFICATION_URLS=smtp://me:[email protected]:587/[email protected] | |
### Replace deprecated `BACKUP_FROM_SNAPSHOT` usage | ||
|
||
Starting with version 2.15.0, the `BACKUP_FROM_SNAPSHOT` feature has been deprecated. | ||
If you need to prepare your sources before the backup is taken, use `exec-pre`, `exec-post` and an intermediate volume: | ||
If you need to prepare your sources before the backup is taken, use `archive-pre`, `archive-post` and an intermediate volume: | ||
|
||
```yml | ||
version: '3' | ||
|
@@ -735,8 +741,8 @@ services: | |
- data:/var/my_app | ||
- backup:/tmp/backup | ||
labels: | ||
- docker-volume-backup.exec-pre=cp -r /var/my_app /tmp/backup/my-app | ||
- docker-volume-backup.exec-post=rm -rf /tmp/backup/my-app | ||
- docker-volume-backup.archive-pre=cp -r /var/my_app /tmp/backup/my-app | ||
- docker-volume-backup.archive-post=rm -rf /tmp/backup/my-app | ||
backup: | ||
image: offen/docker-volume-backup:latest | ||
|
@@ -751,6 +757,23 @@ volumes: | |
backup: | ||
``` | ||
|
||
### Replace deprecated `exec-pre` and `exec-post` labels | ||
|
||
Version 2.19.0 introduced the option to run labeled commands at multiple points in time during the backup lifecycle. | ||
In order to be able to use more obvious terminology in the new labels, the existing `exec-pre` and `exec-post` labels have been deprecated. | ||
If you want to emulate the existing behavior, all you need to do is change `exec-pre` to `archive-pre` and `exec-post` to `archive-post`: | ||
|
||
```diff | ||
labels: | ||
- - docker-volume-backup.exec-pre=cp -r /var/my_app /tmp/backup/my-app | ||
+ - docker-volume-backup.archive-pre=cp -r /var/my_app /tmp/backup/my-app | ||
- - docker-volume-backup.exec-post=rm -rf /tmp/backup/my-app | ||
+ - docker-volume-backup.archive-post=rm -rf /tmp/backup/my-app | ||
``` | ||
|
||
The `EXEC_LABEL` setting and the `docker-volume-backup.exec-label` label stay as is. | ||
Check the additional documentation on running commands during the backup lifecycle to find out about further possibilities. | ||
|
||
### Using a custom Docker host | ||
|
||
If you are interfacing with Docker via TCP, set `DOCKER_HOST` to the correct URL. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters