From a23d2b78158ed33f7ce1353a4f952d903329d342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Sun, 20 Apr 2014 14:19:57 -0500 Subject: [PATCH] Chdir bug --- bash/cronbackup/backup.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bash/cronbackup/backup.sh b/bash/cronbackup/backup.sh index a841a5f..1796c04 100644 --- a/bash/cronbackup/backup.sh +++ b/bash/cronbackup/backup.sh @@ -48,10 +48,16 @@ while read line; do # exclude file EXCLUDE="exclude/${ARGS[1]}" + CHDIR=$(dirname $FILE) + + if [ -d $FILE ]; then + CHDIR="$FILE/../" + fi + if [ -f $EXCLUDE ]; then - tar zcf "$BAKDIR/$BACKUPFILE" -C "$FILE/../" $FILENAME -X $EXCLUDE + tar zcf "$BAKDIR/$BACKUPFILE" -C $CHDIR $FILENAME -X $EXCLUDE else - tar zcf "$BAKDIR/$BACKUPFILE" -C "$FILE/../" $FILENAME + tar zcf "$BAKDIR/$BACKUPFILE" -C $CHDIR $FILENAME fi # count backup file