Right now to recover from a backup with an encrypted HD wallet the user must do something like unlock the wallet with a really long time out and manually trigger a rescan,  otherwise they risk missing some keys when auto-topup cannot run.
{
        LOCK(local_->cs_);
        // First change to using SQLite
        if (!local_->MigrateToSQLite(error)) return utilError{error};
        // Do the migration, and cleanup if it fails
        success = DoMigration(*local_, context, error, res);
    }
    if (success) {
        // Migration successful, unload th locally, then reload it.
        assert(local_.use_count() == 1);
        local_.reset();
        LoadWallet(context, _name, /*load_on_st, options, status, error, warnings);
        res._name = _name;
    } else {
        // Migration failed, cleanup
        // Copy the backup to the actual  dir
        fspath temp_backup_location = fsbridgeAbsPathJoin(GetWalletDir(), backup_filename);
        fscopy_file(backup_path, temp_backup_location, fscopy_optionsnone);
        // Remember this 's dir to remove after unloading
        stdvector<fspath> _dirs;
        _dirs.push_back(fsPathFromString(local_->GetDatabase().Filename()).parent_path());
        // Unload th locally
        assert(local_.use_count() == 1);
        local_.reset();
        // Make list of s to cleanup
        stdvector<stdshared_ptr<CWallet>> created_s;
        if (res.watchonly_) created_s.push_back(stdmove(res.watchonly_));
        if (res.solvables_) created_s.push_back(stdmove(res.solvables_));
        // Get the directories to remove after unloading
        for (stdshared_ptr<CWallet>& w  created_s) {