usernamesaredifficult
New Member
Hi All
I'm looking to be able to correctly evaluate my IF statement and also output what has been backed up into a log file.
In the function at the bottom I am stuck between getting the IF statement to evaluate correctly and managing to log what has been backed up (synchronised with rsync).
If I use the option at the bottom then my IF statement seems to work properly but the tee option freezes the script.
If I comment out the tee option then my IF statement works and the script completes correctly but I’m missing the logging of what has been backed up.
If I use the following then the logging works but the IF statement appears to apply to the tee command, potentially making the IF statement inaccurate (as the backup might fail but the tee command could complete successfully).
I'm looking to be able to correctly evaluate my IF statement and also output what has been backed up into a log file.
In the function at the bottom I am stuck between getting the IF statement to evaluate correctly and managing to log what has been backed up (synchronised with rsync).
If I use the option at the bottom then my IF statement seems to work properly but the tee option freezes the script.
If I comment out the tee option then my IF statement works and the script completes correctly but I’m missing the logging of what has been backed up.
If I use the following then the logging works but the IF statement appears to apply to the tee command, potentially making the IF statement inaccurate (as the backup might fail but the tee command could complete successfully).
Bash:
if sudo rsync -av --exclude '.*' --exclude 'VirtualBox\ VMs' $BACKUPSOURCE $BACKUPDESTINATION | tee -a /home/user/log/rsynctest.txt
Bash:
backupfunction () {
BACKUPSOURCE=/home/user/
BACKUPDESTINATION=/backup/location/user/ # Be aware a directory may be created if it does not exist.
if sudo rsync -av --exclude '.*' --exclude 'VirtualBox\ VMs' $BACKUPSOURCE $BACKUPDESTINATION
then
tee -a /home/user/log/rsynctest.txt
echo "Backed Up"
# return to the script.
return 0
else
echo "Not Backed Up"
FUNCTIONSTATUS="Failed"
echo -e "$SCRIPTNAME\t${FUNCNAME[0]}\t$(date +%x)\t$(date +%X)\t$FUNCTIONSTATUS\tScript terminated. Error encountered attempting to backup." | tee -a /home/user/Logs/ScriptLogTest.txt
# terminate the script with errors.
exit 1
fi
}