我有备份我的网站文件夹和数据库的示例脚本www
。运行时出现此错误
tar: unrecognized option `--transform'
Try `tar --help' or `tar --usage' for more information.
tar: unrecognized option `--transform'
Try `tar --help' or `tar --usage' for more information.
gzip: /home/myhost/backup/file.2014-12-20-2057.tar: No such file or directory
backup finished, file.2014-12-20-2057.tar
相同的脚本在其他主机上运行,没有出现这样的问题。这是脚本
#!/bin/bash
NOW=$(date +"%Y-%m-%d-%H%M")
FILE="file.$NOW.tar"
BACKUP_DIR="/home/myhost/backup/"
WWW_DIR="/home/myhost/public_html/"
DB_USER="user"
DB_PASS="pass"
DB_NAME="db"
DB_FILE="file.$NOW.sql"
WWW_TRANSFORM='s,^home/myhost/public_html,www,'
DB_TRANSFORM='s,^home/myhost/backups,database,'
tar -cf $BACKUP_DIR/$FILE --transform $WWW_TRANSFORM $WWW_DIR
mysqldump -u$DB_USER -p$DB_PASS $DB_NAME > $BACKUP_DIR/$DB_FILE
tar --append --file=$BACKUP_DIR/$FILE --transform $DB_TRANSFORM $BACKUP_DIR/$DB_FILE
rm $BACKUP_DIR/$DB_FILE
gzip -9 $BACKUP_DIR/$FILE
echo 'backup finished', $FILE