From 90c2c8e9a9ee18c68e4ec8c620c65989e02f9df3 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Tue, 9 Jun 2015 23:16:52 +0300 Subject: [PATCH] Add backend to backend migration tool --- pdns/pdnssec.cc | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/pdns/pdnssec.cc b/pdns/pdnssec.cc index ec46daef3..011ed19c2 100644 --- a/pdns/pdnssec.cc +++ b/pdns/pdnssec.cc @@ -1293,6 +1293,7 @@ try cerr<<"add-zone-key ZONE zsk|ksk [bits] [active|passive]"<getPrefix() == cmds[1]) src = b; + if (b->getPrefix() == cmds[2]) tgt = b; + } + if (!src) { + cerr<<"Unknown source backend '"<getPrefix()<<" to "<getPrefix()< domains; + + tgt->getAllDomains(&domains, true); + if (domains.size()>0) + throw PDNSException("Target backend has domain(s), please clean it first"); + + src->getAllDomains(&domains, true); + // iterate zones + for(const DomainInfo& di: domains) { + size_t nr,nc,nm,nk; + DNSResourceRecord rr; + cout<<"Processing '"<createDomain(di.zone)) throw PDNSException("Failed to create zone"); + tgt->setKind(di.zone, di.kind); + tgt->setAccount(di.zone,di.account); + for(const string& master: di.masters) { + tgt->setMaster(di.zone, master); + } + // move records + if (!src->list(di.zone, di.id, true)) throw PDNSException("Failed to list records"); + nr=0; + while(src->get(rr)) { + if (!tgt->feedRecord(rr)) throw PDNSException("Failed to feed record"); + nr++; + } + // move comments + nc=0; + if (src->listComments(di.id)) { + Comment c; + while(src->getComment(c)) { + tgt->feedComment(c); + nc++; + } + } + // move metadata + nm=0; + std::map > meta; + if (src->getAllDomainMetadata(di.zone, meta)) { + std::map >::iterator i; + for(i=meta.begin(); i != meta.end(); i++) { + if (!tgt->setDomainMetadata(di.zone, i->first, i->second)) throw PDNSException("Failed to feed domain metadata"); + nm++; + } + } + // move keys + nk=0; + std::vector keys; + if (src->getDomainKeys(di.zone, 0, keys)) { + for(const DNSBackend::KeyData& k: keys) { + tgt->addDomainKey(di.zone, k); + nk++; + } + } + cout<<"Moved "< tkeys; + if (src->getTSIGKeys(tkeys)) { + for(const struct TSIGKey& tk: tkeys) { + if (!tgt->setTSIGKey(tk.name, tk.algorithm, tk.key)) throw PDNSException("Failed to feed TSIG key"); + ntk++; + } + } + cout<<"Moved "<