This Bash script automates the process of backing up Docker configuration files and as an emphasis on sending beautiful, simple notifications via Telegram. It's designed to be customizable and easy to use, with options for simulating backups before running them for real.
- Backs up specified configuration directories and a docker-compose file
- Calculates total backup size and estimated transfer time
- Sends detailed notifications via Telegram
- Supports simulation mode for testing
- Handles large messages by splitting them when necessary
Before you begin, ensure you have met the following requirements:
- You have a Linux-based system with Bash
- You have installed the following dependencies:
curl
jq
bc
- You have created a Telegram bot and obtained its API token
- You have the Chat ID of the Telegram chat where you want to receive notifications
-
Clone this repository or download the script file.
-
Make the script executable:
chmod +x docker_config_backup.sh
-
Open the script in a text editor and configure the variables at the top of the file:
BACKUP_DIR="" # Directory where backups will be stored CONFIG_DIR="" # Directory containing configuration files to be backed up DOCKER_COMPOSE_FILE="" # Path to the docker-compose.yml file TELEGRAM_TOKEN="" # Telegram Bot API token TELEGRAM_CHAT_ID="" # Telegram Chat ID to send messages to MAX_SIZE_GB=6 # Maximum allowed backup size in GB UPLOAD_SPEED_MBPS=125 # Upload speed in Mbps (default is 1 Gbps = 125 MB/s) TIMEZONE="America/Los_Angeles" # Timezone for date display (e.g., "America/New_York", "Europe/London")
To run the backup script:
./docker_config_backup.sh
To run the script in simulation mode (no actual backup will be created):
./docker_config_backup.sh --sim
You can customize the script by modifying the variables at the top of the file:
BACKUP_DIR
: Set this to the directory where you want to store your backups.CONFIG_DIR
: Set this to the directory containing the Docker configuration files you want to back up.DOCKER_COMPOSE_FILE
: Set this to the path of your docker-compose.yml file.TELEGRAM_TOKEN
: Your Telegram Bot API token.TELEGRAM_CHAT_ID
: The Chat ID where you want to receive Telegram notifications.MAX_SIZE_GB
: The maximum allowed size for the backup in GB.UPLOAD_SPEED_MBPS
: Your upload speed in Mbps, used to calculate estimated transfer times.TIMEZONE
: Set this to your desired timezone (e.g., "America/New_York", "Europe/London", "Asia/Tokyo"). You can find a list of valid timezone names here.
If you encounter issues, try the following:
-
Telegram messages not sending:
- Verify your
TELEGRAM_TOKEN
andTELEGRAM_CHAT_ID
are correct. - Ensure your bot has permission to send messages to the specified chat.
- Verify your
-
Backup size calculation issues:
- Make sure you have read permissions for all directories specified in
CONFIG_DIR
.
- Make sure you have read permissions for all directories specified in
-
Script fails to create backup:
- Check that you have write permissions in the
BACKUP_DIR
. - Ensure you have read permissions for the
CONFIG_DIR
andDOCKER_COMPOSE_FILE
.
- Check that you have write permissions in the
-
Incorrect transfer time estimates:
- Adjust the
UPLOAD_SPEED_MBPS
variable to match your actual upload speed.
- Adjust the
-
Script fails to run:
- Ensure you've made the script executable with
chmod +x docker_config_backup.sh
. - Check that you have
curl
,jq
, andbc
installed on your system.
- Ensure you've made the script executable with
Contributions to improve the script are welcome. Please feel free to submit a Pull Request.