Is it possible to check if an rsync is successful and potentially collect an error if its not?
As I am using --link-dest, I think this may be harder to detect.
I'm fairly new to bash, so any guidance would be appreciated.
Here is a slimmed down version of my script:
#!/bin/bash
set -e
site_host=(
"[email protected]"
"[email protected]"
)
backup_dest=(
"/Users/computername/Desktop/rsync/test1.co.uk"
"/Users/computername/Desktop/rsync/test2.co.uk"
)
now=`date "+%d/%m/%Y %H:%M:%S"`
today=`date +"%d-%m-%Y"`
yesterday=`date -v -1d +"%d-%m-%Y"`
log="/Users/computername/Desktop/rsync/rsync.log"
site_count=${#site_host[@]}
for (( i = 0; i < site_count; i++ )); do
site_source="${site_host[$i]}:~/public_html"
site_dest="${backup_dest[$i]}/$today/"
rsync -zavx -e 'ssh -p22' \
--numeric-ids \
--delete -r \
--link-dest=../$yesterday $site_source $site_dest
echo "$now - File Backup Completed - ${backup_dest[$i]}/$today" >> $log
done
Updated:
#!/bin/bash
set -e
site_host=(
"[email protected]"
"[email protected]"
)
backup_dest=(
"/Users/computername/Desktop/rsync/test1.co.uk"
"/Users/computername/Desktop/rsync/test2.co.uk"
)
now=`date "+%d/%m/%Y %H:%M:%S"`
today=`date +"%d-%m-%Y"`
yesterday=`date -v -1d +"%d-%m-%Y"`
log="/Users/computername/Desktop/rsync/rsync.log"
site_count=${#site_host[@]}
for (( i = 0; i < site_count; i++ )); do
site_source="${site_host[$i]}:~/public_html"
site_dest="${backup_dest[$i]}/$today/"
failures=0
if rsync -zavx -e 'ssh -p22' \
--numeric-ids \
--delete -r \
--link-dest=../$yesterday $site_source $site_dest;
then
echo "$now - File Backup Completed - ${backup_dest[$i]}/$today" >> $log
else
echo "$now - File Backup Failed - ${backup_dest[$i]}/$today" >> $log
failures=$((failures+1))
fi
if ((failures != 0)); then exit 1; fi
done