This Bash script automates the process of exporting all Docker volumes to a compressed archive, creating a portable script for restoring these volumes on another system. It includes the generation of a recover.sh
script for restoring the volumes from the archive and wraps everything into a self-executable import.sh
script for easy transportation and execution.
- Docker installed on the host machine.
- Bash shell environment.
- Sufficient disk space for the backup files.
- Export Volumes: Iterates over all Docker volumes, exporting each to its own tar.gz file.
- Create Unified Archive: Combines all individual volume archives into a single
volumes.tar.gz
file for easy management. - Automated Restoration Script Generation: Generates a
recover.sh
script capable of restoring volumes from the unified archive. - Self-Executable Restoration Script: Produces an
import.sh
script that when executed, will restore all volumes contained within the archive to the destination Docker environment. - Cleanup: Removes all intermediate files to leave only the necessary scripts for backup and restoration.
- Ensure the script is executable:
chmod +x docker-volume-export.sh.sh
- Run the script in your terminal:
./docker-volume-export.sh.sh
- After execution, the script generates
import.sh
. This is the only file needed for restoration.
- Copy
import.sh
to the destination Docker host. - Ensure the script is executable:
chmod +x import.sh
- Execute the script:
./import.sh
- The script will restore all volumes from the archive into the Docker environment.
- The script assumes all Docker volumes can be safely backed up and restored without data integrity issues. It's advisable to stop containers using these volumes during the backup and restoration process to avoid data corruption.
- Ensure there is enough disk space on both the source and destination systems to accommodate the volume backups and their uncompressed contents.
- The script does not handle volumes used by running containers. Ensure containers are stopped to avoid data corruption.
- The script currently does not support selective volume backup or restoration.
This script streamlines the process of Docker volume backup and restoration, making it easier to migrate volumes across environments or keep a backup for disaster recovery purposes. It's a handy tool for developers and system administrators managing Docker volumes.