Plugin: Docker
Description
Enable docker socket communication in the agent and give the following options per container:
- Auto stop & start during backup (toggle)
- Pre-backup command (run the command inside the docker container)
Use Case
Make it easier for us docker folks to back up databases that run inside docker containers.
Alternatives Considered
Shell script hooks, but requires the script to exist on the client.
question, are you running the agent inside a docker container or at the host level?
Host via the official install command, but even in a docker container you can volume mount the docker.socket
what you can do is a Shell Script Hook. there you can tell it what to do before each backup if it should shut down a service.
then you can have a script that shuts down the containers and one that starts after the backup has been run
what you can do is a Shell Script Hook. there you can tell it what to do before each backup if it should shut down a service.
then you can have a script that shuts down the containers and one that starts after the backup has been run
I know that, but the script needs to exist on the host, making it harder to implement for less advanced users. IMHO this whole project is about making backups and restores more noob friendly. Myself I've been running borgmatic for years; just grew tired of being the only one able to perform restores in my team...
I feel like this could get somewhat complicated. People have BBS running in all sorts of ways, agents in docker containers, agents on the host node, bbs installed in a docker container or on the host node. All have different levels of access that would need to be accounted for and might be a little complex to explain to noobie people. A script is just a one time setup and should be done.
If someone wants to sketch out the logic, I can take a stab at it.
If I may a quick question for @rallisf1 , are you wanting to dump the databases before backing them up or wanting to stop the container and back the database up , how was borgmatic setup to do this ?
If I may a quick question for @rallisf1 , are you wanting to dump the databases before backing them up or wanting to stop the container and back the database up , how was borgmatic setup to do this ?
Both. Redis/SQLite stop/start the app container. Postgres/mariadb create dumps.
Ok got it , without using a shell script you could look at using a cron job to deal with the stop/start or even the dump from inside the docker itself , it would mean having to touch every container ,or just stop all containers and back their volumes up ,but I feel like the only good answer would be to snapshot the filesystem to allow for "hot" backups , or full system, partition images with granular file restore , borg is not able to do this and its not practical to change the filesystems on production servers , i am looking for this too , and will be back with more info once I have broken a whole lot of thing testing (-;
One of my goals is to have file system level snapshots for BBS. That way you have consistent point in time backup & recovery.
this isn't 100% what you want, but you can now have multiple DB plugins per schedule. https://github.com/marcpope/borgbackupserver/issues/382
This Docker socket support would be an alternative or additional possiblity to get my backup plan less risky for inconsitent backup data. Same usecase as on my FR for REST API Support via Plugins.
Usecase: I create a backup of my immich instance. This is including postgresql database and all files (photos) in the library directory. Problem at the moment: I cannot set immich into maintenance mode (enable before backup execution and disable after), because I have the bbs-agent running in a docker container on the server. So executing a "docker exec immich_server immich-admin enable-maintenance-mode" command is not possible in the bbs-agent-container at the moment. This would be only possible, if I would have the bbs-agent installed on the server directly, what I do not want to do here in my setup. Immich command overview
Inconsitent backup can be created at the moment while: Backup job is running and the database backup is created at first. While this is running, a user could upload new photos, which would exists on the filesystem and later in the backup of the directory, but not in the database.
With the maintenance mode activated, the user would not be possible to upload any new stuff while the backup is running.
Agree for the addition of docker support.
Whilst I can do db dumps for things, I can't ensure redis is clean right at the correct point, nor can I do an sqlite .dump to ensure that's all clean via shell hook.
My current setup, using backrest, calls a shell script that commands all docker containers to stop/start and it works a treat, and I'd love to migrate to BBS for centralised backup management, but need to ensure I have backup consistency. I'd also love to be able to take backups without shutting things down, but that's another nice to have
Have you tried using the same shell script backrest uses in BBS ?
Yeah, getting command not found errors, whether I use the same script which calls docker, or use other scripts that call sqlite3 .dump.
There are a few reasons for that , if you would like to use it im sure we can get it working , post some more info about the script and its content , as well as some OS info and how the plugin is setup when you have a chance.
See below the script in it's original state that I use for backrest.
In pure testing, I've essentially just minimsed it down to below for testing, and only singeing out a container:
if [[ $1 == "BEFORE" ]]; then
docker stop immich
elif [[ $1 == "AFTER" ]]; then
docker start immich
fi
I'm currently running the bbs-agent in a docker container, so that's what I'm fairly sure is the big limitation.
#!/bin/bash
excluded_services=(
backrest
)
function check_operation_name() {
if [[ "${1}" != "Backup" ]]; then
exit 0
fi
}
function sort_containers() {
# Creates array of all services currently running
mapfile -t all_services < <(docker ps -a --format 'table {{.Names}}' | grep -v NAMES | sort)
# Create an empty array to store the services to control
filtered_services=()
# Loops through all services, and checks against excluded services list
for service in "${all_services[@]}"; do
exclude=false
# Check if the service is in the excluded_services list
for excluded_service in "${excluded_services[@]}"; do
if [ "$service" == "$excluded_service" ]; then
exclude=true
break
fi
done
# If not in the excluded_services list, add it to the filtered_services array
if [ "$exclude" == false ]; then
filtered_services+=("$service")
fi
done
}
function control_containers() {
if [[ $2 == "BEFORE" ]]; then
for i in "${filtered_services[@]}"; do
echo -n "Stopped: " && docker stop "$i"
done
elif [[ $2 == "AFTER" ]]; then
for i in "${filtered_services[@]}"; do
echo -n "Started: " && docker start "$i"
done
fi
}
################################################################################
# Start of Script
################################################################################
# Establish running order
function main() {
check_operation_name "$@"
sort_containers
control_containers "$@"
exit 0 # Pass a successful completion to allow software to run.
}
# Run script
main "$@"
Ok great are you running the bbs agent docker or did you get it installed into a container from the shell script installer ?
Running the bbs agent in docker, using image: marcpope/borgbackupserver-agent:latest
what if the agent were to be installed on the server and the docker data dumped to a folder on the host for backup
#!/bin/bash set -e
STAGING_DIR="/tmp/docker-backups" mkdir -p "$STAGING_DIR"
docker exec -t your_postgres_container pg_dumpall -U postgres > "$STAGING_DIR/postgres_all.sql"
docker exec your_redis_container redis-cli SAVE docker cp your_redis_container:/data/dump.rdb "$STAGING_DIR/redis_dump.rdb"
I hear the requirement for better integration
In my case, I'm running this primarily on my TrueNAS server which runs most of my services, so installing directly is not something I'd particularly like to do if possible.
Additionally, doing a dump is all good and well for services that function with it. I'd ideally like to stop those services to 100% guarantee data is consistent.