Files
backup/docker-restore.sh

47 lines
877 B
Bash

#!/bin/bash
debug=${DEBUG:-}
function copyIfNotDebug {
if [ -z "$debug" ]; then
cp -r "$1" "$2"
else
echo "$1 -> $2"
fi
}
function copyVolumes() {
echo "Copying volumes..."
local volumes=($(find "$1/volumes" -maxdepth 1 -mindepth 1 -type d))
for volume in "${volumes[@]}"; do
local dest="${volume#"$1"/volumes*}"
copyIfNotDebug "$volume" "$dest"
done
}
function copyStacks() {
echo "Copying stacks..."
local stacks=($(find "$1/stacks" -maxdepth 1 -mindepth 1 -type d))
for stack in "${stacks[@]}"; do
local dest="${stack#"$1"/stacks*}"
copyIfNotDebug "$stack" "$dest"
done
}
function main() {
local archive="$1"
local dir="${archive%*.tar.gz}"
# unzip the archive.
tar -xvf "$archive"
# copy stacks and volumes to their locations.
copyVolumes "$dir"
copyStacks "$dir"
# cleanup
rm -rf "$dir"
}
main "$@"