Improve handling of EOF during backup-related DB operations.

This is motivated by the following CI test failure: http://juju-ci.vapour.ws:8080/job/functional-ha-backup-restore/1165/console