Created
May 13, 2022 21:43
-
-
Save mmontuori/27505b4b5d90484347f0351869949989 to your computer and use it in GitHub Desktop.
This gist contains a bash script which backs up all volumes found in docker volume list except the auto generated ones. The backup is executed in the /opt/backup directory, but it can be customized as needed together with other variables.
This file contains 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 | |
volumes=`docker volume list | grep -v DRIVER | awk '{ print $2 }'` | |
backup_dir="/opt/backup" | |
volumes_to_backup="" | |
backup_retention_dyas="10" | |
for volume in $volumes; do | |
name_length=`echo $volume | wc -m` | |
if [ "$name_length" == "65" ]; then | |
continue | |
fi | |
volumes_to_backup="$volumes_to_backup $volume" | |
done | |
for volume_to_backup in $volumes_to_backup; do | |
echo "backing up $volume_to_backup -> ${backup_dir}..." | |
docker run -v ${volume_to_backup}:/volume -v /opt/backup:/backup --rm loomchild/volume-backup backup ${volume_to_backup}-`date +%Y%m%d` | |
done | |
echo "cleaning old files..." | |
find ${backup_dir} -mtime +${backup_retention_dyas} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment