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.
size_t CWalletKeypoolCountExternalKeys() const
{
    AssertLockHeld(cs_);
    auto legacy_spk_man = GetLegacyScriptPubKeyMan();
    if (legacy_spk_man) {
        return legacy_spk_man->KeypoolCountExternalKeys();
    }
    unsigned int count = 0;
    for (auto spk_man  m_external_spk_managers) {
        count += spk_man.second->GetKeyPoolSize();
    }
    return count;
}
unsigned int CWalletGetKeyPoolSize() const
{
    AssertLockHeld(cs_);
    unsigned int count = 0;
    for (auto spk_man  GetActiveScriptPubKeyMans()) {
        count += spk_man->GetKeyPoolSize();
    }
    return count;
}
bool CWalletTopUpKeyPool(unsigned int kpSize)
{
    LOCK(cs_);
    bool res = true;
    for (auto spk_man  GetActiveScriptPubKeyMans()) {
        res &= spk_man->TopUp(kpSize);
    }
    return res;