I have a backup script for my server that mostly works. Only the the rsync commands throw an error in the log I can't find a solution to.
Here's part of my script (I removed the working stuff):
#!/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 user@server.domain:/`
if [[ $? != 0 ]]; then
log "Error during upload of backup"
else
log "Uploading of backup OK"
fi
`scp $LOG user@server.domain:/`
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 user@server.domain.de
# Sending mail
`echo "Done" | mutt -s "Backup completed on $TIMEEND" -i $LOG user@domain.com`
# Removing backup folder
echo -e "Removing temporary folder"
log "Removing temporary folder..."
`rm $BKDIR -rf`
The script is running as root via cronjob. Everything is working fine, except the rsync commands. Every single one of them is writing the following error into the logfile:
20:19:38: Saving Minecraft...
/home/roots/scripts/backup.sh: line 126: sending: command not found
20:21:07:
20:21:40: Backup of www-data files
/home/roots/scripts/backup.sh: line 141: sending: command not found
/home/roots/scripts/backup.sh: line 142: sending: command not found
20:22:58:
20:23:03: Copying FHEM backups
/home/roots/scripts/backup.sh: line 157: sending: command not found
All 4 rsync commands have the exact same parameters except for the source and destination paths.
The server is running Ubuntu 16.04.2 LTS (Xenial Xerus).
Anyone got an idea what I did wrong?
rsync
really at/usr/bin/rsync
? (test this withwhich rsync
in a shell) – thrig Jun 22 '17 at 19:22