Created
February 27, 2025 18:11
-
-
Save iu2frl/e62a820a04109029e5cd0840c82a098c to your computer and use it in GitHub Desktop.
Backup of Docker volumes and Portainer settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Telegram Bot Credentials | |
| TELEGRAM_BOT_TOKEN="" | |
| TELEGRAM_CHAT_ID="" | |
| # Backup API | |
| BACKUP_API_URL="https://127.0.0.1:9443/api/backup" | |
| API_KEY="" | |
| # Backup Paths | |
| BACKUP_DIR="/home/iu2frl/docker_backup" | |
| PORTAINER_BACKUP="$BACKUP_DIR/portainer_snapshot.tar.gz" | |
| DOCKER_VOLUMES_BACKUP="$BACKUP_DIR/docker_volumes.tar" | |
| DOCKER_VOLUMES_COMPRESSED="$BACKUP_DIR/docker_volumes.tar.lz" | |
| # Create folder if not exist | |
| mkdir -p "$BACKUP_DIR" | |
| # Notify start | |
| curl -F text="Server Casa" "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage?chat_id=$TELEGRAM_CHAT_ID" | |
| # Request Portainer backup | |
| curl -k -X POST "$BACKUP_API_URL" \ | |
| -H "X-API-Key:$API_KEY" \ | |
| -H "Content-Type: application/json; charset=utf-8" \ | |
| -d '{ "password": "" }' --output "$PORTAINER_BACKUP" | |
| # Send Portainer backup to Telegram | |
| curl -F document=@"$PORTAINER_BACKUP" "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendDocument?chat_id=$TELEGRAM_CHAT_ID" | |
| # Backup Docker volumes | |
| tar -cf "$DOCKER_VOLUMES_BACKUP" /var/lib/docker/volumes | |
| # Compress Docker volumes backup | |
| sudo plzip -4 -o "$DOCKER_VOLUMES_COMPRESSED" "$DOCKER_VOLUMES_BACKUP" | |
| # Send compressed Docker volumes backup to Telegram | |
| curl -F document=@"$DOCKER_VOLUMES_COMPRESSED" "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendDocument?chat_id=$TELEGRAM_CHAT_ID" | |
| # Cleanup | |
| rm "$DOCKER_VOLUMES_BACKUP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment