在 shell 备份脚本上通过 tar 压缩文件夹时遇到问题。
# Path to backup directories
DIRS="/home/bob /var/www /root"
# Store todays date
NOW=$(date +"%F")
# Store backup path
BACKUP="/backup"
BACKUPDIR="$BACKUP/daily/calendar/$NOW"
# Backup file name hostname.time.tar.gz
BFILE="dirs.tar.gz"
$TAR -zcvf ${BACKUPDIR}/${BFILE} "${DIRS}"
echo $TAR -zcvf ${BACKUPDIR}/${BFILE} "${DIRS}"
我不断收到的错误是
/bin/tar: Removing leading `/' from member names
/bin/tar: /home/bob /var/www /root: Cannot stat: No such file or directory
/bin/tar: Exiting with failure status due to previous errors
/bin/tar -zcvf /backup/daily/calendar/2012-12-13/dirs.tar.gz /home/bob /var/www /root
如果我在终端上运行最后一个 echo 命令,它可以正常工作。在脚本中调用时不起作用