There are a few things you want to backup:

  1. Container / stack configurations
  2. Data volumes
  3. Secrets like .env files

There are multiple approaches for backing up your portainer.

1. Backing up docker volumes

# List your Docker volumes
docker volume ls
 
# Backup a specific volume (example: MongoDB data)
docker run --rm -v <volume_name>:/volume -v $(pwd):/backup alpine \
    tar czf /backup/<volume_name>.tar.gz -C /volume .

2. Ready made scripts

This is for backing up all containers, images and volumes into a tarball.

docker run --rm \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v $(pwd):/backup \
  loomchild/volume-backup backup all-containers.tar.gz

3. container specific backup

Instead of doing a full backup, backing up your database is safer.

Mongodb

docker exec <mongodb_container> mongodump --archive=/dump/mongo.archive
docker cp <mongodb_container>:/dump/mongo.archive ./mongo-backup.archive

4. cron jobs

you could run cron jobs that backup your vps every night, and then later you can pull those backups manually to your homepc.

I am not going to go into this deep, besides that i have them on my vps, and i can pull these backups locally by doing the following 2 commands:

rsync -avz root@<VPS_IP>:/root/backups/system/ ~/vps-backups/system/
rsync -avz root@<VPS_IP>:/root/backups/mongodb/ ~/vps-backups/mongodb/