rdiff-backup错误:脚本不断退出并出现错误

时间:2013-06-13 11:32:23

标签: bash scripting rdiff-backup

我最近被介绍过bash脚本...所以,我已经使用我的高级盗窃课程将附加的脚本放在一起。它运行...并退出“/ xxx /未安装。你不是root!我已经安装了rdiff-backup和sshfs并且正常工作。这些命令在命令行上可以自行运行,但在脚本中,嗯..你能看一看并知道吗?PS我从我在这里和其他一些地方找到的脚本中复制了很多这样的内容。

<code>
#!/bin/bash
# Version 1.5
# Prior to running this make sure you have ssh-keygen -t rsa to generate a key, then
# ssh username@target "mkdir .ssh/;chmod 700 .ssh"
# scp .ssh/id_rsa.pub username@target:.ssh/authorized_keys
#
# then check you can login and accept the ssh key
# ssh username@target "ls -la"
#
# Key things to remember, no spaces in pathnames, and try to use full paths (beginning with / )
#
# variables determine backup criteria

DATESTAMP=`date +%d%m%y`
USERNAME=username #remote site username here
TARGET=remote.ip.here #add the ip v4 address of the target
INCLUDES=/path/to/file/includes.txt #this is a txt file containing a list of directories you want backed up
EXCLUDES="**" #this is a list of files etc you want to skip
BACKUPLOG=/path/to/logfile/in/home/backuplog${DATESTAMP}.txt
OLDERTHAN=20W #change 20 to reflect how far back you want backups to exist
# to activate old backup expiry, uncomment the line below
#RMARGS=" --force --remove-older-than ${OLDERTHAN}"
TARGETMAIL="yourmailaddress@your.domain"

HOSTNAME=`hostname` #Dont change this!
TMPDIR=/backups Change this to the source folder
TARGETFOLDER=/backups change this to the TARGET folder

ARGS=" -v0 --terminal-verbosity 0 --exclude-special-files --exclude-other-filesystems --no-compression -v6"

# detecting distro and setting the correct path
if [ -e /etc/debian_version ];then
    NICE=/usr/bin/nice
elif [ -e /etc/redhat-release ];then
    NICE=/bin/nice
fi


if [ -e /tmp/backup.lock ];then
    exit 0
fi
touch /tmp/backup.lock
touch -a ${BACKUPLOG}

cd /
/bin/mkdir -p ${TMPDIR}

/usr/bin/sshfs -o idmap=user -o ${USERNAME}@${TARGET}:/${TARGETFOLDER} ${TMPDIR} &>${BACKUPLOG}
# if you get errors mounting this then try 
# mknod /dev/fuse -m 0666 c 10 229

for ITEMI in ${INCLUDES} ; do
                    ARGS="${ARGS} --include ${ITEMI} "
done
for ITEME in ${EXCLUDES} ; do
                    ARGS="${ARGS} --exclude-regexp '${ITEME}' "
done
# the --exclude ** / is a hack because it wont by default do multiple dirs, so use --include for all dirs then exclude everything else and sync / - if you dont understand dont worry 
# ref: http://www.mail-archive.com/rdiff-backup-users@nongnu.org/msg00311.html
#echo /usr/bin/rdiff-backup ${ARGS} --exclude \'**\' / ${TMPDIR}/ &&

cat ${INCLUDES} | while read DIR; do
            ${NICE} -19 /usr/bin/rdiff-backup --exclude '**' ${DIR} ${TMPDIR}/ &>${BACKUPLOG}
            if [ $? != 0 ]; then
                    echo "System Backup Failed" | mutt -s "Backup Log: System Backup Failed, Log attached!" -a ${BACKUPLOG} ${TARGETMAIL}
                    exit 1;
            fi
    done


#${NICE} -19 /usr/bin/rdiff-backup ${ARGS} --exclude '**' / ${TMPDIR}/ &>${BACKUPLOG} &&
echo Removing backups older than ${RMARGS}
${NICE} -19 /usr/bin/rdiff-backup -v0 --terminal-verbosity 0  ${RMARGS} ${TMPDIR}/ &>${BACKUPLOG}
/bin/umount ${TMPDIR} && /bin/rm -rf ${TMPDIR}/ &>${BACKUPLOG}
echo "System Backup Run" | mutt -s "Backup Log: System Backup Done!" -a ${BACKUPLOG} ${TARGETMAIL}

rm /tmp/backup.lock
rm ${BACKUPLOG}

对不起,无法粘贴,无法附上...... BLIKSEM!

感谢任何输入......一个学习曲线的地狱! 问候, 乙

0 个答案:

没有答案