Recently the backup script I've been using for years has started to give me trouble. The part that's problematic boils down to this:
for DIR in "${BACKUP_DIRS[@]}"; do
rsync --acls --archive --delete \
--link-dest=${DIR} \
--stats \
--verbose \
--rsh="ssh -o BatchMode=yes -i ${KEY}" \
"${USER}"@${HOST}:"${DIR}" "${BACKUP_DIR}/"
done
Now the problem I have is that on the first (and only the first) directory listed in ${BACKUP_DIRS[@]}
, rsync
exits with an error:
ssh: Could not resolve hostname <host>: Name or service not known
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(226) [Receiver=3.1.3]
An error occurred during backup of <dir>.
Any clues on how to resolve this are very much appreciated.
As suggested by András Korn, the problem was that the DNS resolver takes too long.
By adding and extra DNS lookup before invoking
rsync
, the query result will be fast whenrsync
is called, since the query result has been cached.DNS lookup can be forced using
getent
,host
,dig
or by pinging the host.