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