我关注了这个问题: How to backup filesystem with tar using a bash script?
但是当我运行脚本时它给出了以下错误:
: not found/backup.sh: 2: /etc/init.d/backup.sh:
: not found/backup.sh: 5: /etc/init.d/backup.sh:
: not found/backup.sh: 7: /etc/init.d/backup.sh:
: not found/backup.sh: 10: /etc/init.d/backup.sh:
: not found/backup.sh: 12: /etc/init.d/backup.sh:
/etc/init.d/backup.sh: 13: /etc/init.d/backup.sh: Syntax error: "(" unexpected
这是我的脚本:
#!/bin/bash
#TODAY=$(date +%F)
#HOST=$(hostname)
mybackupname="backup-fullsys-$(date +%Y-%m-%d).tar.gz"
# Record start time by epoch second
start=$(date '+%s')
# List of excludes in a bash array, for easier reading.
excludes=(--exclude=/FILES/Media/Programs/Mint/Backup/$mybackupname)
excludes+=(--exclude=/proc)
excludes+=(--exclude=/lost+found)
excludes+=(--exclude=/sys)
excludes+=(--exclude=/mnt)
excludes+=(--exclude=/MEDIA)
excludes+=(--exclude=/BACKUP)
excludes+=(--exclude=/FILES)
if ! tar -czf "$mybackupname" "${excludes[@]}" /; then
status="tar failed"
elif ! mv "$mybackupname" FILES/Media/Programs/Mint/Backup/ ; then
status="mv failed"
else
status="success: size=$(stat -c%s backups/filesystem/$mybackupname) duration=$((`date '+%s'` - $start))"
# Log to system log; handle this using syslog(8).
logger -t backup "$status"
有人看到我哪里出错了吗?
最佳答案
正如“那个人”评论的那样,这里的解决方案是在 bash 文件上运行 dos2unix convert 命令:
sudo dos2unix /etc/init.d/backup.sh
并使用 bash 命令而不是 sh 命令运行它:
sudo bash /etc/init.d/backup.sh
关于linux - tar 备份错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30854039/