use defer to make sure the lock gets released, even when the backup fails

This can happen when there are temporary network glitches.