Fix backup and restore issues (mainly with missing database document)