我的脚本旨在使用ssh收集文件并通过网络备份(因为它是防火墙唯一未阻止的内容),然后删除任何超过30天的备份。但是,当代码运行时,我收到此错误消息:
接收增量文件列表rsync:mkdir “/ var / home / username_local / BackupTo / username / 2015-08-10”失败:没有 文件或目录(2)rsync错误:文件IO(代码11)中的错误 main.c(576)[receiver = 3.0.6]
我正在使用的代码如下:
#!/bin/bash
#User who's files are being backed up
BNAME=username
#directory to back up
BDIR=/home/username/BackThisUp
#directory to backup to
BackupDir=/var/home/username_local/BackupTo
#user
RUSER=$USER
#SSH Key
KEY=/var/home/username_local/.ssh
#Backupname
RBackup=`date +%F`
#Backup Server
BServ=backup.server
#Path
LPATH='Data for backup'
#date
DATE=`date +%F`
#Transfer new backups
rsync -avpHrz -e "ssh -i $KEY" $BNAME@$BServ:$BDIR $BackupDir/$BNAME/$DATE
find $BackupDir/$BNAME -type d -ctime +30 -exec rm -rf {} \;
编辑:当我添加时,问题解决了:
mkdir $BackupDir/$BNAME > /dev/null 2>&1
rsync之前的
答案 0 :(得分:0)
我认为rsync不会写入不存在的目标目录。 您可以使用
添加rsyncimport nltk
sentence = [("the", "DT"), ("little", "JJ"), ("yellow", "JJ"), ("dog", "NN"), ("barked","VBD"), ("at", "IN"), ("the", "DT"), ("cat", "NN")]
pattern = """NP: {<DT>?<JJ>*<NN>}
VBD: {<VBD>}
IN: {<IN>}"""
NPChunker = nltk.RegexpParser(pattern)
result = NPChunker.parse(sentence)
result.draw()
但仅当mkdir的变量已知安全时。这可以是代码注入,例如,如果你的$ BackupDir是从脚本外部提供的。
答案 1 :(得分:0)
另一个技巧是将实际的rsync(在远程服务器上启动)添加到... mkdir:
rsync -avpHrz --rsync-path "mkdir -m 700 $BackupDir/$BNAME/$DATE && rsync" -e "ssh -i $KEY" $BNAME@$BServ:$BDIR $BackupDir/$BNAME/$DATE