This script scans the usual Docker Volumes path, compresses them to .tar.gz archive and sends it to a Telegram chat
- Clone the repo
- Install requirements with
pip install -r ./requirements.txt - Configure the BOT
API_KEYin the environment variables (for example:export BOT_TOKEN="000000:aaaaaBBBBBccccc") - Configure the destination chat in
BOT_DEST(for example:export BOT_DEST="000000:aaaaaBBBBBccccc") - (optional) Configure the volumes root path in
ROOT_DIR - (optional) Configure a temporary path in
TMP_DIR - Configure the Portainer API URL in
BACKUP_API_URL(for example:export BACKUP_API_URL="https://your-portainer-instance/api/backup") - Configure the Portainer API key in
API_KEY(for example:export API_KEY="your-portainer-api-key") - Execute the script
python3 ./main.py
- Clone the repo
- Build the image with
sudo docker build . -t docker-backup:latest - Create a
.envfile with the environment variables (one per each line) - Execute the image with
sudo docker run --env-file=.env -v /var/lib/docker/volumes:/root/backup -it docker-backupmaking sure to map the proper physical folder to/root/backup
Link: iu2frl/portainer-volumes-telegram-backup/general
You can map as many elements of the ROOT_DIR as you wish, for example:
- Environment:
ROOT_DIR=/root/backup/ - Volumes:
-v /local/volume/path:/root/backup/someService -v /local/other/volume:/root/backup/someOtherService
This example creates a backup of everything in /var/snap/docker/common/var-lib-docker/volumes plus /home/iu2frl/guacamole every Sunday at 2am, execution log is sent to /tmp/port-backup-log.txt
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
0 2 * * Sun docker run -itd -v /var/lib/docker/volumes:/root/backup:ro --env-file=/home/iu2frl/portainer-backup.env --rm --pull=always iu2frl/portainer-volumes-telegram-backup:latest > /tmp/port-backup-log.txt 2>&1# .env file example
# Telegram bot token
BOT_TOKEN=000000:aaaaaBBBBBccccc
# Telegram destination chat ID
BOT_DEST=123456789
# Custom message to send before files list (optional)
CUST_MSG=Your custom message here
# Root directory for Docker volumes (optional)
ROOT_DIR=/var/snap/docker/common/var-lib-docker/volumes,/var/lib/docker/volumes,/root/backup
# Temporary directory for storing backups (optional)
TMP_DIR=/tmp
# Portainer API URL for requesting backups
BACKUP_API_URL=https://your-portainer-instance/api/backup
# Portainer API key
API_KEY=your-portainer-api-key