Skip to content

Commit

Permalink
handle files of any path
Browse files Browse the repository at this point in the history
  • Loading branch information
Guiorgy committed Feb 8, 2024
1 parent f12728a commit 62c781d
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions vackup
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ vackup load IMAGE VOLUME
EOF
}

fulldirname() {
DIRECTORY=$(dirname "$1")

case "$DIRECTORY" in
\/*) ;;
\.*) ;& # fallthrough
*) DIRECTORY="$(pwd)/$DIRECTORY" ;;
esac
DIRECTORY=$(readlink -m "$DIRECTORY")

echo "$DIRECTORY"
}

if [ -z "$1" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
usage
exit 0
Expand All @@ -66,12 +79,13 @@ cmd_export() {

# TODO: check if file exists on host, if it does
# create a option for overwrite and check if that's set
# TODO: if FILE_NAME starts with / we need to error out
# unless we can translate full file paths

DIRECTORY=$(fulldirname "$FILE_NAME")
FILE_NAME=$(basename "$FILE_NAME")

if ! docker run --rm \
-v "$VOLUME_NAME":/vackup-volume \
-v "$(pwd)":/vackup \
-v "$DIRECTORY":/vackup \
busybox \
tar -zcvf /vackup/"$FILE_NAME" /vackup-volume;
then
Expand Down Expand Up @@ -100,12 +114,13 @@ cmd_import() {

# TODO: check if file exists on host, if it does
# create a option for overwrite and check if that's set
# TODO: if FILE_NAME starts with / we need to error out
# unless we can translate full file paths

DIRECTORY=$(fulldirname "$FILE_NAME")
FILE_NAME=$(basename "$FILE_NAME")

if ! docker run --rm \
-v "$VOLUME_NAME":/vackup-volume \
-v "$(pwd)":/vackup \
-v "$DIRECTORY":/vackup \
busybox \
tar -xvzf /vackup/"$FILE_NAME" -C /;
then
Expand Down

0 comments on commit 62c781d

Please sign in to comment.