Python script that makes backups and updates your docker services using Watchtower image
1.6K
This is a python script that makes backups and updates your docker services using Watchtower image
If Watchtower updates a docker service and the new image version breaks your container, who you gonna call?! Maintainer's got your back! It will backup your configs for each specified docker service, before watchtower makes an update.
For each docker service, when backing up - Maintainer will pull out the current image digest, so in the need to go back to a backed up version, you can spin up a container using the image digest and bind the backed up config folder. And voila - you now are back on the older (working) version of the service. Also Maintainer can be set to run on a predefined schedule.
--label=com.centurylinklabs.watchtower.enable=false to all containers that you don't want Watchtower to updateThe tag latest is multi-arch, so you can use it for any architecture.
IMPORTANT: you must create the following file named config.yml and place it in a folder, that will be binded to a volume. Otherwise you cannot use this docker image.
general_settings:
## DELETE IF NOT NEEDED. Image digest to use for watchtower. It should be in the format of "sha256:<SOME_LONG_STRING>". Note: if this field is omitted then the latest watchtower image will be used.
watchtower_digest: <PASTE IMAGE DIGEST HERE>
## should the script make a backup and update when starting for the first time. Note: it will also create a file ".initialBackup" in your bound backup folder. If that file is present, then on the next restart of Maintainer, the backup will **NOT** be run. Additional Note: This setting will not affect the "backup_schedule" settings
initial_backup: true
## Number of backup sessions to keep. NOTE: if not specified, by default only the latest 3 backups will be kept
backups_count: 3
## should the archive be compressed, or just stored
use_compression: false
## Compression level of the backup archives (if use_compression is set to true) - from 1 to 9
compression: 5
## DELETE THE ONE YOU DON'T NEED. This is the schedule when you want the script to run and make backup / update
backup_schedule:
## DELETE IF NOT NEEDED
weekly:
## available values are MON, TUE, WED, THU, FRI, SAT, SUN.
day: <INPUT DAY HERE>
## Use HH:mm format and wrap the time in quatation marks e.g. "14:28"
time: <HH:mm>
## DELETE IF NOT NEEDED
daily:
## Use HH:mm format and wrap the time in quatation marks e.g. "14:28"
time: <HH:mm>
## DELETE IF NOT NEEDED. This schedule will run the backup/update procedure, on the specified day on the last week of the current month
last_day_of_month:
## available values are MON, TUE, WED, THU, FRI, SAT, SUN.
day: <INPUT DAY HERE>
## Use HH:mm format and wrap the time in quatation marks e.g. "14:28"
time: <HH:mm>
## add as many services you'd like
services_to_backup:
postgres: ## NOTE: this name must be the same name as the docker container, that is currently listed in the docker service (use `docker ps -a`)! This will also be the name of the backed up archive.
## add the root folder where the service has it's files that you want to backup; Example: /appData/pihole; NOTE: This depends on what folder you've bound when creating the container. It must start with path /appData/
root_directory: /appData/<RELATIVE PATH TO CONF FOLDER OF SERVICE>
## should Maintainer stop the container before doing the backup. Note: If omitted it will default to true
stop_container: true
## DELETE IF YOU WANT TO BACKUP ALL CONTENT IN THE root_directory. This is a list of folder and files to disregard (will be ignored when making a backup). Note: just specify the name of the folder or file - NO NEED to add the absolute path.
exclusions:
- subfolder1
- log_file.txt
- otherFolder
pihole: ## NOTE: this name must be the same name as the docker container, that is currently listed in the docker service (use `docker ps -a`)! This will also be the name of the backed up archive.
## add the root folder where the service has it's files that you want to backup; Example: /appData/pihole; NOTE: This depends on what folder you've bound when creating the container. It must start with path /appData/
root_directory: /appData/<RELATIVE PATH TO CONF FOLDER OF SERVICE>
## should Maintainer stop the container before doing the backup. Note: If omitted it will default to true
stop_container: false
## ## DELETE IF YOU WANT TO BACKUP ALL CONTENT IN THE root_directory. list of folder and files to disregard (will be ignored when making a backup). Note: just specify the name of the folder or file - NO NEED to add the absolute path.
exclusions:
- exampleFolder1
- db_file.sql3
discord_webhooks: ## DELETE IF NOT USED. These settings make the whole process more visible, by pushing current progress of the backup/update process
maintainer: <PASTE YOUR DISCORD WEBHOOK HERE>
watchtower: <PASTE YOUR DISCORD WEBHOOK HERE>
The config.yml can also be found here.
docker create \
--name=maintainer \
-d \
--label=com.centurylinklabs.watchtower.enable=false \
-e TZ=Europe/London \
-v /root/path/to/your/docker/service/config/folder:/appData \
-v /path/to/backups/:/backup \
-v /path/to/your/yaml/config/file:/yaml \
-v /var/run/docker.sock:/var/run/docker.sock
--restart unless-stopped
dokeraj/maintainer:latest
| flag | Function |
|---|---|
--label=com.centurylinklabs.watchtower.enable=false | Mandatory. This flag will tell Watchtower to not update Maintainer. NOTE: If this is NOT set, then Maintainer will be stopped mid-updating and you don't want that! |
-e TZ=Europe/London | Mandatory. Set it to your timezone. Note: If not set properly, the scheduled backup/update will not be ran at the specified time! |
-v /root/path/to/your/docker/service/config/folder:/appData | Mandatory. This bind should point to where you have all your config folders for all docker containers. Note: It is important that you bind the ROOT folder, where all the config docker service folders are located. That way you can simply use the /appData/<your_service_conf_folder> (in the root_directory field, that is found in the config.yml file ) |
-v /path/to/backups/:/backup | Mandatory. This bind should be pointing to where you'd like the backups to be saved on your local machine. |
-v /path/to/your/yaml/config/file:/yaml | Mandatory. This bind should point to where you have placed your config.yml file, so Maintainer can read it on startup. |
-v /var/run/docker.sock:/var/run/docker.sock | Mandatory. This bind should be left as it is - it helps the docker container to get access to docker server environment and monitor for events. |
You can find the source at this location
Content type
Image
Digest
Size
21.5 MB
Last updated
over 4 years ago
docker pull dokeraj/maintainer