Skip to content

Commit

Permalink
Add labels (#34)
Browse files Browse the repository at this point in the history
* Added more labels

* Updated docs

* Add override feature to labels
  • Loading branch information
Minituff authored Oct 16, 2023
1 parent 51bf1bc commit 331995d
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 82 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM docker:24.0.6-cli

# Install dependencies
RUN apk add bash rsync tzdata dos2unix
RUN apk add bash rsync tzdata dos2unix jq

# Copy all necessary files into the container (from /pkg in the repository to /app in the container)
COPY pkg app
Expand Down Expand Up @@ -37,5 +37,8 @@ ENV USE_DEFAULT_RSYNC_ARGS="true"
# Apply custom rsync args (in addition to the default args)
ENV RSYNC_CUSTOM_ARGS=""

# Require the Docker Label `nautical-backup.enable=true` to be present on each contianer or it will be skipped.
ENV REQUIRE_LABEL="false"

# Run the entry script and pass all variables to it
ENTRYPOINT [ "bash", "-c", "exec ./entry.sh \"${@}\"", "--"]
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ A simple Docker volume backup tool.
<br>

[![Pulls from DockerHub](https://img.shields.io/docker/pulls/minituff/nautical-backup?logo=docker)](https://hub.docker.com/r/minituff/nautical-backup)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/minituff/nautical-backup)](https://hub.docker.com/r/minituff/nautical-backup)
[![Docker Image Size (tag)](https://img.shields.io/docker/image-size/minituff/nautical-backup/latest)](https://hub.docker.com/r/minituff/nautical-backup)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/minituff/nautical-backup?label=latest%20version)](https://hub.docker.com/r/minituff/nautical-backup)
[![Docker Image Size (tag)](https://img.shields.io/docker/image-size/minituff/nautical-backup/latest?label=size)](https://hub.docker.com/r/minituff/nautical-backup)



Expand All @@ -23,6 +23,7 @@ Full documentation is available at [https://minituff.github.io/nautical-backup](

Docker Compose
```yaml
version: '3'
services:
nautical-backup:
image: minituff/nautical-backup:0.1.1
Expand Down
122 changes: 74 additions & 48 deletions docs/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Nautical provides configuration in the form of Docker enviornment variables.

See the [Installation Section](./installation.md), which contains a few examples of applying enviornment variables.

### Enviornment Variable vs Label Priority
If a container has an Enviornment Variable applied as well as a conflicting Label, then:
> The continer Label takes priority over the global Natical enviornment variable.
## Time Zone

Sets the time-zone to be used by the CRON schedule. If this environment variable is not set, Nautical will use the default time-zone: `Etc/UTC`.
Expand Down Expand Up @@ -29,83 +33,103 @@ Tell Nautical to skip backup of containers in this list.

This list can either be the container `name` or full `id`.

> **Default**: *empty*
> **Default**: *empty* <small>(no skips)</small>
=== "Example 1"
```properties
SKIP_CONTAINERS=container-name1,container-name2,container-name3
```

=== "Example 2"
```properties
SKIP_CONTAINERS=container-name1,056bd2e970c1338782733fdbf1009c6e158c715d0d105b11de88bd549430e7f5
```

```properties
SKIP_CONTAINERS=container-name1,container-name2,container-name3
```
```properties
SKIP_CONTAINERS=container-name1,056bd2e970c1338782733fdbf1009c6e158c715d0d105b11de88bd549430e7f5
```
!!! tip "Getting the full container ID"
Usally, it's easier to just use the `container-name`, but if you need to use the full ID, these commands will help:

* `docker ps --no-trunc`
* `docker inspect <container name>`

<small>🔄 This is the same action as the [Skip Containers](./labels.md#skip) label, but applied globally.</small>

## Require Label
Require the Docker ^^Label^^ `nautical-backup.enable=true` to be present on *each* contianer or it will be skipped.

> **Default**: false
```properties
REQUIRE_LABEL=true
```

See the [Labels Enable Section](./labels.md#enable-nautical) for more details.

## Override Source Directory
Allows a source directory and container-name that do not match.

> **Default**: *empty*
> **Default**: *empty* <small>(use container name)</small>
> **Format**: `<container-name>:<local source folder name>` <small>(comma seperated for multiple items)</small>
Normally a container is backed up *only* when the `container-name` is the exact same as the `source folder name`.

Example 1:
=== "Example 1"

For example, a container named `Pi.Alert` will be skipped with a source directory name of `pialert`.
To fix this, we can override the source directory name so that it does not need to match the container name.
For example, a container named `Pi.Alert` will be skipped with a source directory name of `pialert`.
To fix this, we can override the source directory name so that it does not need to match the container name.

```properties
OVERRIDE_SOURCE_DIR=Pi.Alert:pialert
```
```properties
OVERRIDE_SOURCE_DIR=Pi.Alert:pialert
```

Example 2:
=== "Example 2"

We can override multiple containers if we seperate them with a comma.
```properties
OVERRIDE_SOURCE_DIR=example1:example1-new-source-data,ctr2:ctr2-new-source
```
<small> The example above would yield the following results:</small>
We can override multiple containers if we seperate them with a comma.
```properties
OVERRIDE_SOURCE_DIR=example1:example1-new-source-data,ctr2:ctr2-new-source
```
<small> The example above would yield the following results:</small>

| Container Name | Old Source Directory | New Source Directory |
| -------------- | -------------------- | ---------------------------- |
| example1 | `src/example1` | `src/example1-new-dest-data` |
| ctr2 | `src/ctr2` | `src/newdest` |
| Container Name | Old Source Directory | New Source Directory |
| -------------- | -------------------- | ---------------------------- |
| example1 | `src/example1` | `src/example1-new-dest-data` |
| ctr2 | `src/ctr2` | `src/newdest` |

<small>🔄 This is the same action as the [Override Source Directory](./labels.md#override-source-directory-name) label, but applied globally.</small>

## Override Destination Directory
Changes the destination backup name to be something other than the container name.

> **Default**: *empty*
> **Default**: *empty* <small>(use container name)</small>
> **Format**: `<container-name>:<new destination folder name>` <small>(comma seperated for multiple items)</small>
Normally, a container is backed to a folder with the ^^same name^^ as the `container-name`.

Example 1:
=== "Example 1"

For example, let's say we have a container named `Pi.Alert`. By default, the container will be backed up to a folder named `Pi.Alert`.
If we want to change this destination folder name to be `pialert`, we can do that using overrides.
For example, let's say we have a container named `Pi.Alert`. By default, the container will be backed up to a folder named `Pi.Alert`.
If we want to change this destination folder name to be `pialert`, we can do that using overrides.

```properties
OVERRIDE_DEST_DIR=Pi.Alert:pialert
```
```properties
OVERRIDE_DEST_DIR=Pi.Alert:pialert
```


Example 2:
=== "Example 2"

```properties
OVERRIDE_DEST_DIR=example1:example1-new-dest-data,ctr2:newdest
```
```properties
OVERRIDE_DEST_DIR=example1:example1-new-dest-data,ctr2:newdest
```

<small> The example above would yield the following results:</small>
<small> The example above would yield the following results:</small>

| Container Name | Old Destination Directory | New Destination Directory |
| -------------- | ------------------------- | ----------------------------- |
| example1 | `dest/example1` | `dest/example1-new-dest-data` |
| ctr2 | `dest/ctr2` | `dest/newdest` |
| Container Name | Old Destination Directory | New Destination Directory |
| -------------- | ------------------------- | ----------------------------- |
| example1 | `dest/example1` | `dest/example1-new-dest-data` |
| ctr2 | `dest/ctr2` | `dest/newdest` |

<small>🔄 This is the same action as the [Override Destination Directory](./labels.md#override-destination-directory-name) label, but applied globally.</small>

## Report file
Enable or Disable the automatically generated report file.
Expand All @@ -119,7 +143,7 @@ REPORT_FILE=true
## Skip Stopping Containers
Bypass stopping the container before performing a backup. This can be useful for containers with minimal configuration.

> **Default**: *empty*
> **Default**: *empty* <small>(no containers will be skipped)</small>
```properties
SKIP_STOPPING=example1,example2
Expand All @@ -129,6 +153,9 @@ SKIP_STOPPING=example1,example2

Only do this on containers you know for certain do not need to be shutdown before backup.


<small>🔄 This is the same action as the [Stop Before Backup](./labels.md#stop-before-backup) label, but applied globally.</small>

## Backup on Start
Will immediatly perform a backup when the container is started in addition to the CRON sheduled backup.

Expand Down Expand Up @@ -167,21 +194,20 @@ USE_DEFAULT_RSYNC_ARGS=false
## Custom rsync Arguments
Apply custom `rsync` args <small>(in addition to the [default](#use-default-rsync-arguments) args)</small>

> **Default**: *empty*
> **Default**: *empty* <small>(no custom rsync args will be applied)</small>
The `RSYNC_CUSTOM_ARGS` will be inserted after the `$DEFAULT_RSYNC_ARGS` as shown:
```bash
rsync $DEFAULT_RSYNC_ARGS $RSYNC_CUSTOM_ARGS $src_dir/ $dest_dir/
```


There are many `rsync` arguments and customizations that be be used here.

Examples:
```properties
# Don't backup any .log or any .txt files
RSYNC_CUSTOM_ARGS=--exclude='*.log' --exclude='*.txt'
```
=== "Example 1"
```properties
# Don't backup any .log or any .txt files
RSYNC_CUSTOM_ARGS=--exclude='*.log' --exclude='*.txt'
```

<br>
<br>
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<br/><br/>
<a href="https://hub.docker.com/r/minituff/nautical-backup">
<img alt="Pulls from DockerHub" src="https://img.shields.io/docker/pulls/minituff/nautical-backup?logo=docker" />
<img alt="Docker Image Version (latest semver)" src="https://img.shields.io/docker/v/minituff/nautical-backup?label=latest%20version" />
<img alt="Docker Image Size (tag)" src="https://img.shields.io/docker/image-size/minituff/nautical-backup/latest?label=size" />
</a>
</p>

Expand Down
134 changes: 134 additions & 0 deletions docs/labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
Docker Labels allow us to apply settings to Nautical on a per-container basis. Instead of applying [enviornment variables](./arguments.md), we can apply the label to the each container seperately.

### How to add labels

Here are a few examples of how to add labels to a Docker container.
Remember, these labels can be added to any container <small> (other than Nautical itself).</small>

=== "Docker Compose Example 1"
```yaml
version: '3'
services:
# Service config ...
labels:
- "nautical-backup.enable=true"
- "nautical-backup.stop-before-backup=true"
```

=== "Docker Compose Example 2"
```yaml
version: '3'
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "53:53/tcp"
- "53:53/udp"
- "80:80/tcp"
volumes:
- './etc-pihole:/etc/pihole'
- './etc-dnsmasq.d:/etc/dnsmasq.d'
labels:
- "nautical-backup.enable=true"
- "nautical-backup.stop-before-backup=true"
```

=== "Docker Run Example"
```bash
docker run --name example-image \
-l nautical-backup.enable=true \
-l nautical-backup.stop-before-backup=true \
my-image:latest
```

=== "Docker Run Example 2"
```bash
docker run -d \
--name pihole \
-p 53:53/tcp -p 53:53/udp \
-p 80:80 \
-e TZ="America/Chicago" \
-v "${PIHOLE_BASE}/etc-pihole:/etc/pihole" \
-v "${PIHOLE_BASE}/etc-dnsmasq.d:/etc/dnsmasq.d" \
-l nautical-backup.enable=true \
-l nautical-backup.stop-before-backup=true \
pihole/pihole:latest
```

### Label vs Enviornment Variable Priority
If a container has an Enviornment Variable applied as well as a conflicting Label, then:
> The continer Label takes priority over the global Natical enviornment variable.
## Enable Nautical
With the [Require Label](./arguments.md#require-label) enviornment variable set to `true`, then all containers will be skipped unless they have this label.

> **Default If Missing**: true
```properties
nautical-backup.enable=false
```

If the [Require Label](./arguments.md#require-label) enviornment variable is *missing* or set to `false`, then [this label](#enable-nautical) will not be needed since the container will be backed up anyway.

## Skip
Skip any containers completely if this label is present.

> **Default If Missing**: false
```properties
nautical-backup.skip=true
```

<small>🔄 This is the same action as the [Skip Containers](./arguments.md#skip-containers) variable, but applied only to this container.</small>

## Stop Before Backup

With this label applied, the container will not be stopped before performing a backup.

> **Default If Missing**: false
```properties
nautical-backup.stop-before-backup=true
```

!!! warning "Not stoppping containers can produce *corrupt* backups."
Containers with databases--particularly SQL--need to be shutdown before backup.

Only do this on containers you know for certain do not need to be shutdown before backup.

<small>🔄 This is the same action [Skip Stopping Containers](./arguments.md#skip-stopping-containers) variable, but applied only to this container.</small>

## Override Source Directory Name

Changes the source directory name that Nautical will look for.

By default, Nautical will look for the source directory that is the same name as the container name.

> **Default If Missing**: *empty* <small>(use container name)</small>
=== "Example 1"
```properties
nautical-backup.override-source-dir=new_folder_name
```

=== "Example 2"
To backup the container `Pi.Alert`, the source directory name must be named `Pi.Alert`, but we can use the override to allow a backup of the folder named `pialert`.
```properties
nautical-backup.override-source-dir=pialert
```

<small>🔄 This is the same action as the [Override Source Directory](./arguments.md#override-source-directory) variable, but applied only to this container.</small>

## Override Destination Directory Name
Changes the destination/output directory name that Nautical will create during backups.

By default, Nautical will create destination directory that is the same name as the container name.

> **Default If Missing**: *empty* <small>(use container name)</small>
```properties
nautical-backup.override-destination-dir=new_folder_name
```

<small>🔄 This is the same action as the [Override Destination Directory](./arguments.md#override-destination-directory) variable, but applied only to this container.</small>
9 changes: 0 additions & 9 deletions docs/todo.md

This file was deleted.

Loading

0 comments on commit 331995d

Please sign in to comment.