2020-02-18 21:59:18 +08:00
|
|
|
---
|
|
|
|
layout: default
|
|
|
|
title: Get-Zones subcommand
|
|
|
|
---
|
|
|
|
|
|
|
|
# get-zones (was "convertzone")
|
|
|
|
|
|
|
|
DNSControl has a stand-alone utility that will contact a provider,
|
|
|
|
download the records of one or more zones, and output them to a file
|
|
|
|
in a variety of formats.
|
|
|
|
|
2020-05-22 22:20:10 +08:00
|
|
|
`get-zones` relies on command line parameters and `creds.json`
|
|
|
|
exclusively. It does not use `dnsconfig.js`. This is to assist
|
|
|
|
bootstrapping a new system.
|
2020-02-18 21:59:18 +08:00
|
|
|
|
2020-05-22 22:20:10 +08:00
|
|
|
## Use case 1: Bootstrapping a new system
|
|
|
|
|
|
|
|
If you are moving a DNS zone from a provider to DNSControl, this
|
|
|
|
command will do most of the work for you by downloading the records
|
|
|
|
and writing them out in `dnsconfig.js`-format. It is intended to be
|
|
|
|
"a decent first draft", only requiring minimal editing.
|
|
|
|
|
|
|
|
Use `--format=djs` or `--format=js` (djs is recommended).
|
|
|
|
|
|
|
|
Minor editing is required. Not all record formats are supported.
|
|
|
|
SOA records are commented out, since most providers do not support it.
|
|
|
|
BIND supports it, but requires the data to be entered as meta data.
|
|
|
|
|
|
|
|
The `NAMESERVER()` command is generated commented out. This is usually
|
|
|
|
not needed as DNSControl can get more accurate information via the
|
|
|
|
API. Remove the comments only to override the DNS service provider.
|
|
|
|
|
|
|
|
## Use case 2: Generating BIND ZONE files
|
|
|
|
|
|
|
|
The `--format=zone` generates BIND-style Zonefiles. Pseudo records not
|
|
|
|
supported by BIND are generated as comments.
|
|
|
|
|
|
|
|
This format is useful when moving zonedata between providers, since
|
|
|
|
the format is relatively universal.
|
|
|
|
|
|
|
|
This format is also useful for generating backups of DNS zones. Unlike
|
|
|
|
making a backup of the `dnsconfig.js`, this is the raw records, which
|
|
|
|
may be useful.
|
|
|
|
|
|
|
|
## Use case 3: TAB separated values
|
|
|
|
|
|
|
|
The goal of `--format=tsv` is to provide a high-fidelity format that is easy
|
|
|
|
enough to parse with `awk`.
|
|
|
|
|
|
|
|
## Use case 4: List zones
|
|
|
|
|
|
|
|
If a provider supports it, `--format=nameonly` lists the names of the
|
|
|
|
zones at the provider.
|
|
|
|
|
|
|
|
|
|
|
|
## Syntax
|
2020-02-18 21:59:18 +08:00
|
|
|
|
|
|
|
dnscontrol get-zones [command options] credkey provider zone [...]
|
|
|
|
|
|
|
|
--creds value Provider credentials JSON file (default: "creds.json")
|
2020-03-10 23:32:47 +08:00
|
|
|
--format value Output format: js djs zone tsv nameonly (default: "zone")
|
2020-02-18 21:59:18 +08:00
|
|
|
--out value Instead of stdout, write to this file
|
2020-02-25 20:23:40 +08:00
|
|
|
--ttl value Default TTL (0 picks the zone's most common TTL) (default: 0)
|
2020-02-18 21:59:18 +08:00
|
|
|
|
|
|
|
ARGUMENTS:
|
|
|
|
credkey: The name used in creds.json (first parameter to NewDnsProvider() in dnsconfig.js)
|
|
|
|
provider: The name of the provider (second parameter to NewDnsProvider() in dnsconfig.js)
|
|
|
|
zone: One or more zones (domains) to download; or "all".
|
|
|
|
|
2020-02-22 03:59:47 +08:00
|
|
|
FORMATS:
|
2020-03-10 23:32:47 +08:00
|
|
|
--format=js dnsconfig.js format (not perfect, just a decent first draft)
|
|
|
|
--format=djs js with disco commas
|
2020-03-09 23:42:48 +08:00
|
|
|
--format=zone BIND Zonefile format
|
|
|
|
--format=tsv TAB separated value (useful for AWK)
|
|
|
|
--format=nameonly Just print the zone names
|
2020-02-22 03:59:47 +08:00
|
|
|
|
2020-03-10 23:32:47 +08:00
|
|
|
The columns in --format=tsv are:
|
2020-02-22 03:59:47 +08:00
|
|
|
FQDN (the label with the domain)
|
|
|
|
ShortName (just the label, "@" if it is the naked domain)
|
|
|
|
TTL
|
|
|
|
Record Type (A, AAAA, CNAME, etc.)
|
|
|
|
Target and arguments (quoted like in a zonefile)
|
|
|
|
|
2020-03-10 23:32:47 +08:00
|
|
|
The --ttl flag only applies to zone/js/djs formats.
|
2020-02-25 20:23:40 +08:00
|
|
|
|
2020-05-22 22:20:10 +08:00
|
|
|
## Examples
|
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
dnscontrol get-zones myr53 ROUTE53 example.com
|
|
|
|
dnscontrol get-zones gmain GANDI_V5 example.comn other.com
|
|
|
|
dnscontrol get-zones cfmain CLOUDFLAREAPI all
|
|
|
|
dnscontrol get-zones -format=tsv bind BIND example.com
|
2020-03-10 23:32:47 +08:00
|
|
|
dnscontrol get-zones -format=djs -out=draft.js glcoud GCLOUD example.com`,
|
2020-02-18 21:59:18 +08:00
|
|
|
|
2020-03-10 23:32:47 +08:00
|
|
|
Read a zonefile, generate a JS file, then use the JS file to see how
|
|
|
|
different it is from the zonefile:
|
2020-02-18 21:59:18 +08:00
|
|
|
|
2020-05-22 22:20:10 +08:00
|
|
|
dnscontrol get-zone --format=djs -out=foo.djs bind BIND example.org
|
2020-03-10 23:32:47 +08:00
|
|
|
dnscontrol preview --config foo.js
|
2020-02-18 21:59:18 +08:00
|
|
|
|
2020-05-22 22:20:10 +08:00
|
|
|
# Developer Notes
|
2020-02-18 21:59:18 +08:00
|
|
|
|
|
|
|
This command is not implemented for all providers.
|
|
|
|
|
|
|
|
To add this to a provider:
|
|
|
|
|
2020-02-28 05:29:16 +08:00
|
|
|
**Step 1. Document the feature**
|
2020-02-18 21:59:18 +08:00
|
|
|
|
|
|
|
In the `*Provider.go` file, change the setting to implemented.
|
|
|
|
|
|
|
|
* OLD: ` providers.CanGetZones: providers.Unimplemented(),`
|
|
|
|
* NEW: ` providers.CanGetZones: providers.Can(),`
|
|
|
|
|
2020-02-28 05:29:16 +08:00
|
|
|
**Step 2. Update the docs**
|
2020-02-18 21:59:18 +08:00
|
|
|
|
|
|
|
```
|
|
|
|
go generate
|
|
|
|
```
|
|
|
|
|
2020-02-28 05:29:16 +08:00
|
|
|
**Step 3. Implement the `GetZoneRecords` function**
|
2020-02-18 21:59:18 +08:00
|
|
|
|
|
|
|
Find the `GetZoneRecords` function in the `*Provider.go` file.
|
|
|
|
|
2020-02-29 22:07:05 +08:00
|
|
|
It currently returns `fmt.Errorf("not implemented")`.
|
2020-02-18 21:59:18 +08:00
|
|
|
|
|
|
|
Instead, it should gather the records from the provider
|
|
|
|
and return them as a list of RecordConfig structs.
|
|
|
|
|
|
|
|
The code to do that already exists in `GetDomainCorrections`.
|
|
|
|
You should extract it into its own function (`GetZoneRecords`), rather
|
2020-05-22 22:20:10 +08:00
|
|
|
than having it be buried in the middle of `GetDomainCorrections`.
|
2020-02-18 21:59:18 +08:00
|
|
|
`GetDomainCorrections` should call `GetZoneRecords`.
|
|
|
|
|
|
|
|
Once that is done the `get-zone` subcommand should work.
|
|
|
|
|
2020-05-22 22:20:10 +08:00
|
|
|
**Step 4. Optionally implement the `ListZones` function**
|
2020-02-18 21:59:18 +08:00
|
|
|
|
2020-02-22 03:59:47 +08:00
|
|
|
If the `ListZones` function is implemented, the "all" special case
|
|
|
|
will be activated. In this case, listing a single zone named `all`
|
|
|
|
will query the provider for the list of zones.
|
2020-02-18 21:59:18 +08:00
|
|
|
|
|
|
|
(Technically what is happening is by implementing the `ListZones`
|
|
|
|
function, you are completing the `ZoneLister` interface for that
|
|
|
|
provider.)
|
2020-02-29 22:07:05 +08:00
|
|
|
|
|
|
|
Implementing the `ListZones` function also activates the `check-creds`
|
|
|
|
subcommand for that provider. Please add to the provider documentation
|
|
|
|
a list of error messages that people might see if the credentials are
|
|
|
|
invalid. See `docs/_providers/gcloud.md` for examples.
|