Skip to content

Instantly share code, notes, and snippets.

@Codycody31
Last active May 26, 2024 02:57
Show Gist options
  • Select an option

  • Save Codycody31/7984ac8f0a3be5d30121e1473e8266da to your computer and use it in GitHub Desktop.

Select an option

Save Codycody31/7984ac8f0a3be5d30121e1473e8266da to your computer and use it in GitHub Desktop.
Restore backed up volumes from CapRover
#!/bin/bash
# Define the backup tarball
backup_tarball="captain_volumes_backup.tar.gz"
# Check if the backup tarball exists
if [ ! -f $backup_tarball ]; then
echo "Backup tarball $backup_tarball not found."
exit 1
fi
# Extract the backup tarball
tar xzf $backup_tarball
# List all extracted tarballs
volume_tarballs=$(ls captain--*.tar.bz2)
totalvolumes=$(echo "$volume_tarballs" | wc -l)
restoredvolumes=0
echo "Starting restoration of $totalvolumes volumes."
# Restore each volume from its tarball
for tarball in $volume_tarballs; do
volume_name=$(basename $tarball .tar.bz2)
if docker run --rm -i -v $volume_name:/volume --log-driver none loomchild/volume-backup restore -c bz2 < ./$tarball; then
restoredvolumes=$((restoredvolumes + 1))
echo "Successfully restored: $volume_name"
else
echo "Failed to restore: $volume_name"
fi
done
echo "Successfully restored $restoredvolumes out of $totalvolumes volumes."
# Clean up extracted tarballs
rm captain--*.tar.bz2
echo "Restoration process completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment