Created
August 20, 2024 15:09
-
-
Save craigcabrey/dbb492a53d33556ef7dec691036f7c6f to your computer and use it in GitHub Desktop.
Creates a tarball of the contents of a Longhorn volume
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/sh | |
REPLICA_NAME="$(basename $1)" | |
SIZE="$(jq .Size /var/lib/longhorn/replicas/$REPLICA_NAME/volume.meta)" | |
TEMP_DIR="$(mktemp -d)" | |
echo "Backing up replica $REPLICA_NAME" | |
CONTAINER_ID=$(docker run -d --rm -v /dev:/host/dev -v /proc:/host/proc -v /var/lib/longhorn/replicas/$REPLICA_NAME:/volume --privileged longhornio/longhorn-engine:v1.6.2 launch-simple-longhorn $REPLICA_NAME $SIZE) | |
echo "Container is $CONTAINER_ID" | |
echo "Waiting for block device to enumerate" | |
until [ -b /dev/longhorn/$REPLICA_NAME ]; do | |
sleep 5 | |
echo "Still not available..." | |
done | |
echo "Block device available" | |
mount -o ro /dev/longhorn/$REPLICA_NAME $TEMP_DIR | |
tar czvf $REPLICA_NAME.tar.gz $TEMP_DIR | |
umount $TEMP_DIR | |
docker stop $CONTAINER_ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment