我的服务器有一个大部分有效的备份脚本。只有 rsync 命令在日志中抛出错误,我找不到解决方案。
这是部分我的脚本(我删除了工作内容):
#!/bin/bash
TIMESTAMP=`date +%Y%m%d_%H%M`
BKROOT="/home/roots/backups"
BKDIR="/home/roots/backups/$TIMESTAMP"
LOG="$BKROOT/backup_$TIMESTAMP.log"
function log ()
{
now=$(date +"%T")
echo -e "$now: $1"
}
echo -e "Starting backup..."
if [ ! -d "$BKDIR" ]; then
echo -e "Creating Backup directory $BKDIR..."
mkdir -p $BKDIR
mkdir -p $BKDIR/games
mkdir -p $BKDIR/games/minecraft
fi
# Redirect all output to log
exec >> $LOG
exec 2>&1
log "Saving Minecraft..."
`/usr/bin/rsync -av /var/games/minecraft $BKDIR/games/minecraft --exclude 'plugins/dynmap/web'`
log
# Sleeping 10 seconds to allow file access
sleep 10
# Compressing backup
log "Compressing backup to $BKROOT/backup_$TIMESTAMP.tar.gz..."
`/bin/tar czvfP $BKROOT/backup_$TIMESTAMP.tar.gz "$BKDIR"`
if [[ $? != 0 ]]; then
log "Error during compression"
else
log "Compression OK"
fi
# Uploading backup to Backup storage
log "Uploading backup and log to Backup storage..."
`/usr/bin/scp $BKROOT/backup_$TIMESTAMP.tar.gz [email protected]:/`
if [[ $? != 0 ]]; then
log "Error during upload of backup"
else
log "Uploading of backup OK"
fi
`scp $LOG [email protected]:/`
if [[ $? != 0 ]]; then
log "Error during upload of backup log"
else
log "Uploading of backup log OK"
fi
log
TIMEEND=`date "+%m/%d/%Y @ %H:%M"`
# Logging free space on backup location
echo 'df -h' | sftp [email protected]
# Sending mail
`echo "Done" | mutt -s "Backup completed on $TIMEEND" -i $LOG [email protected]`
# Removing backup folder
echo -e "Removing temporary folder"
log "Removing temporary folder..."
`rm $BKDIR -rf`
该脚本通过 cronjob 以 root 身份运行。除了 rsync 命令之外,一切工作正常。他们每个人都将以下错误写入日志文件:
20:19:38:保存 Minecraft...
/home/roots/scripts/backup.sh:第 126 行:发送:未找到命令
20:21:07:
20:21:40:www 数据文件
/home的备份/roots/scripts/backup.sh:第 141 行:发送:未找到命令
/home/roots/scripts/backup.sh:第 142 行:发送:未找到命令
20:22:58:
20:23:03:正在复制 FHEM备份
/home/roots/scripts/backup.sh:第 157 行:发送:找不到命令
除了源路径和目标路径之外,所有 4 个 rsync 命令都具有完全相同的参数。
服务器运行 Ubuntu 16.04.2 LTS (Xenial Xerus)。
有人知道我做错了什么吗?
答案1
你有这样的行:
`/usr/bin/rsync -av /var/games/minecraft $BKDIR/games/minecraft --exclude 'plugins/dynmap/web'`
反引号的意思是执行命令的输出在他们之间。所以rsync
命令运行,创建一些输出,shell尝试执行该输出。只需删除反引号即可:
/usr/bin/rsync -av /var/games/minecraft $BKDIR/games/minecraft --exclude 'plugins/dynmap/web'