Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling other container tools then docker #24

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

Vackup: (contraction of "volume backup")

Easily backup and restore Docker volumes using either tarballs or container images.
It's designed for running from any host/container where you have the docker CLI.
Easily backup and restore OCI volumes using either tarballs or container images.
It's designed for running from any host/container where you have a docker capable CLI. It has been tested with Docker, Podman and Finch.
To use that feature, just set the env variable CONTAINERDIST in your shell session or invoke it direclty in the cmd:
`$ CONTAINERDIST="podman" ./vackup.sh`

Note that for open files like databases,
it's usually better to use their preferred backup tool to create a backup file,
Expand Down
38 changes: 21 additions & 17 deletions vackup
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Docker Volume File Backup and Restore Tool
# Docker/Container Volume File Backup and Restore Tool
# Easily tar up a volume on a local (or remote) engine
# Inspired by CLIP from Lukasz Lach

Expand All @@ -24,7 +24,8 @@ trap 'handle_error $LINENO' ERR
usage() {
cat <<EOF

"Docker Volume Backup". Replicates image management commands for volumes.
"Docker/Container Volume Backup". Replicates image management commands for volumes.
You can also use an alternative Docker CMD compatible solution, if you set the env variable CONTAINERDIST. Example would be Podman

export/import copies files between a host tarball and a volume. For making
volume backups and restores.
Expand Down Expand Up @@ -83,10 +84,10 @@ fulldirname() {

case "$DIRECTORY" in
/*) ;;
.*) ;& # fallthrough
.*) ;; # fallthrough
markaltmann marked this conversation as resolved.
Show resolved Hide resolved
*) DIRECTORY="$(pwd)/$DIRECTORY" ;;
esac
DIRECTORY=$(readlink -m "$DIRECTORY")
DIRECTORY=$(readlink -f "$DIRECTORY")

echo "$DIRECTORY"
}
Expand All @@ -104,7 +105,7 @@ cmd_export() {
error usage 'Not enough arguments'
fi

if ! docker volume inspect --format '{{.Name}}' "$VOLUME_NAME";
if ! "$CONTAINER" volume inspect --format '{{.Name}}' "$VOLUME_NAME";
then
error "Volume $VOLUME_NAME does not exist"
fi
Expand All @@ -115,7 +116,7 @@ cmd_export() {
DIRECTORY=$(fulldirname "$FILE_NAME")
FILE_NAME=$(basename "$FILE_NAME")

if ! docker run --rm \
if ! "$CONTAINER" run --rm \
-v "$VOLUME_NAME":/vackup-volume \
-v "$DIRECTORY":/vackup \
busybox \
Expand All @@ -135,10 +136,10 @@ cmd_import() {
error usage 'Not enough arguments'
fi

if ! docker volume inspect --format '{{.Name}}' "$VOLUME_NAME";
if ! "$CONTAINER" volume inspect --format '{{.Name}}' "$VOLUME_NAME";
then
echo "Warning: Volume $VOLUME_NAME does not exist, creating..."
docker volume create "$VOLUME_NAME"
"$CONTAINER" volume create "$VOLUME_NAME"
fi

if [ ! -r "$FILE_NAME" ]; then
Expand All @@ -154,7 +155,7 @@ cmd_import() {
DIRECTORY=$(fulldirname "$FILE_NAME")
FILE_NAME=$(basename "$FILE_NAME")

if ! docker run --rm \
if ! "$CONTAINER" run --rm \
-v "$VOLUME_NAME":/vackup-volume \
-v "$DIRECTORY":/vackup \
busybox \
Expand All @@ -174,24 +175,24 @@ cmd_save() {
error usage 'Not enough arguments'
fi

if ! docker volume inspect --format '{{.Name}}' "$VOLUME_NAME";
if ! "$CONTAINER" volume inspect --format '{{.Name}}' "$VOLUME_NAME";
then
error "Volume $VOLUME_NAME does not exist"
fi

if ! docker run \
if ! "$CONTAINER" run \
-v "$VOLUME_NAME":/mount-volume \
busybox \
cp -Rp /mount-volume/. /volume-data/;
then
error 'Failed to start busybox container'
fi

CONTAINER_ID=$(docker ps -lq)
CONTAINER_ID=$("$CONTAINER" ps -n 1 -q)

docker commit -m "saving volume $VOLUME_NAME to /volume-data" "$CONTAINER_ID" "$IMAGE_NAME"
"$CONTAINER" commit -m "saving volume $VOLUME_NAME to /volume-data" "$CONTAINER_ID" "$IMAGE_NAME"

docker container rm "$CONTAINER_ID"
"$CONTAINER" container rm "$CONTAINER_ID"

echo "Successfully copied volume $VOLUME_NAME into image $IMAGE_NAME, under /volume-data"
}
Expand All @@ -204,13 +205,13 @@ cmd_load() {
error usage 'Not enough arguments'
fi

if ! docker volume inspect --format '{{.Name}}' "$VOLUME_NAME";
if ! "$CONTAINER" volume inspect --format '{{.Name}}' "$VOLUME_NAME";
then
echo "Warning: Volume $VOLUME_NAME does not exist, creating..."
docker volume create "$VOLUME_NAME"
"$CONTAINER" volume create "$VOLUME_NAME"
fi

if ! docker run --rm \
if ! "$CONTAINER" run --rm \
-v "$VOLUME_NAME":/mount-volume \
"$IMAGE_NAME" \
cp -Rp /volume-data/. /mount-volume/;
Expand All @@ -221,6 +222,9 @@ cmd_load() {
echo "Successfully copied /volume-data from $IMAGE_NAME into volume $VOLUME_NAME"
}

# Use other container management distributions, defaults to docker. Tested with Podman.
CONTAINER=${CONTAINERDIST:-docker}
# Standard command of the script
COMMAND="$1"
case "$COMMAND" in
export) cmd_export "$@" ;;
Expand Down