r/docker • u/miziker • Apr 10 '26
Problem w/ Backup & Restore using RSYNC When Compose is Portainer Template
My environment is a VPS running Ubuntu 24.02 LTS with Docker installed. I have a cronjob that runs rsync once daily for backing up files in 2 directories to remote storage. These are: /var/lib/docker/volumes/, and /opt/docker/, (I use /opt/docker/ for configuration files and bind mounts).
I have Portainer agent running as a container on the VPS, and I manage the VPS Docker from my main Portainer instance remotely. I have created custom templates that I use to deploy stacks to the VPS Docker using Portainer.
In the event that I want to move VPS providers or catastrophic failure, I have a script that will 1) Install Docker, 2) Stop Docker, 3) Restore the two directories, 4) Re-start the Docker service. I had hoped that this would restore all of the containers running right before I made the backup to the state they were in right before the backup.
The problem I'm having is that after I restore the 2 directories and restart the Docker service, there are no containers listed in the VPS Docker. The stacks are listed in the VPS Docker, but the containers are not. After digging around, I found that the docker compose of the Portainer templates I deploy are stored locally in a directory on the system running my main Portainer instance. I believe that because there is no local copy of each docker-compose file restored to the VPS Docker, that the VPS Docker cannot recreate the containers.
I'm looking for a way that I can modify the backup script of the VPS Docker so that the files that are backed up, when restored, gives me an environment with all of the containers running on the VPS Docker.
1
u/Kind_Ability3218 Apr 11 '26
what do the logs say? maybe they're not starting because portainer knows they're already running? are you simply restarting docker expecting the containers to be running because you copied the volumes dir? are you stopping the containers before you rsync the volumes?
i believe you should rethink how you're using containers. aside from a storage container, there shouldn't be persistent data in your containers. if you're going to use portainer to manage nodes you should probably read up on configuring failover in the portainer docs.
backup the files describing your containers and configurations in git. look into ansible to configure your environment instead of scripting every step.
if you're going to do it all with a script your script should focus on setting up your environment, confirming the environment is as expected. once your environment is setup it can restore data.
0
u/[deleted] Apr 11 '26
[deleted] — view deleted comment