0
votes

My script is designed to gather files and back them up across the network using ssh (because it is the only thing unblocked by the firewall) and then delete any backups that are over 30 days old. However, when the code is run I receive this error message:

receiving incremental file list rsync: mkdir "/var/home/username_local/BackupTo/username/2015-08-10" failed: No such file or directory (2) rsync error: error in file IO (code 11) at main.c(576) [receiver=3.0.6]

The code I am using is below:

#!/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 {} \;

EDIT: The problem was solved when I added:

mkdir $BackupDir/$BNAME > /dev/null 2>&1

before the rsync

2

2 Answers

0
votes

I think rsync will not writ to non existing destination directories. You could prepend your rsync with an

ssh $BNAME@$BServ "mkdir $BackupDir/$BNAME/$DATE"

but only if the variables for mkdir are known safe. This can be a code injection if e.g. your $BackupDir is provided externally from the script.

0
votes

Another trick would be to prepend the actual rsync (started on the remote server) with... mkdir:

rsync -avpHrz --rsync-path "mkdir -m 700 $BackupDir/$BNAME/$DATE && rsync" -e "ssh -i $KEY" $BNAME@$BServ:$BDIR $BackupDir/$BNAME/$DATE