Here is a script that you can use to stop the containers AND have it only perform those functions when there is a backup being performed. I found out that Duplicati runs the before/after scripts even when doing something like a restore:
#!/bin/bash
# docker stop script
OPERATIONNAME=$DUPLICATI__OPERATIONNAME
if [ "$OPERATIONNAME" == "Backup" ]
then
docker stop <container_name1> <container_name2> <...>
else
exit 0
fi
Just make a second copy and change it to docker start ...
of course for the “after” script.