feat: Adds restore script.

This commit is contained in:
2025-04-17 14:00:16 -04:00
parent ff4a9a14e7
commit 189f2c36de
3 changed files with 63 additions and 7 deletions

46
docker-restore.sh Normal file
View File

@@ -0,0 +1,46 @@
#!/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 "$@"