A shell script for safely backing up Docker container volumes. The script automatically handles stopping and restarting containers as needed during the backup process.
- Automatically stops and restarts containers during backup
- Creates timestamped backups of all volumes
- Moves previous backups to trash instead of deleting them
- Verbose logging option
- System logging integration
- Handles multiple volumes per container
- Docker
- sudo access
trash-cli
package for safe file deletion- ZSH shell
- Clone this repository
- Make the script executable:
chmod +x docker_volume_backup.sh
./docker_volume_backup.sh --output-dir DIR [--verbose] CONTAINER_NAME
--output-dir DIR
: Directory where backups will be stored--verbose
: Enable verbose loggingCONTAINER_NAME
: Name of the Docker container to backup
./docker_volume_backup.sh --output-dir /path/to/backups --verbose my-container
Backups are organized as follows:
output-dir/
└── container-name/
└── volume-name/
└── YYYYMMDD_HHMMSS.tar.gz
- Validates container existence and running state
- Ensures output directory exists
- Handles backup failures gracefully
- Automatically restores container state on error
- Uses system logger (via
logger
) - Optional verbose console output
- Timestamps all log messages
MIT License