Created
January 19, 2024 22:26
-
-
Save emilienbidet/f8898789d5aa5bbe9bc4469f4a26dbed to your computer and use it in GitHub Desktop.
Backup all docker volumes bash script
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 | |
# Create the backup directory if it doesn't exist | |
mkdir -p "./backup" | |
# Get the list of all Docker volumes | |
VOLUMES=$(docker volume ls --quiet) | |
# Iterate over each volume and perform the backup | |
for VOLUME_ID in $VOLUMES; do | |
VOLUME_NAME=$(docker volume inspect --format '{{.Name}}' "$VOLUME_ID" | sed 's/^\///') # Extract volume name | |
BACKUP_FILE="/backup/$VOLUME_NAME.tar.gz" | |
echo "Backing up $VOLUME_NAME to $BACKUP_FILE" | |
# Perform the backup | |
docker run --rm -v "$VOLUME_NAME":/data -v ./backup:/backup alpine tar czf "$BACKUP_FILE" -C /data . | |
done | |
echo "Backup completed for all volumes." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Easy bash script to archive all your docker volumes.
Simply run