Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "dumpallzones" command to dump all zones in BIND9 format #2

Merged
merged 2 commits into from Jun 18, 2018

Conversation

Daniel15
Copy link
Contributor

Adds a new dumpallzones command to dump all zones in BIND9 format. This is useful to backup an entire ClouDNS account.

Technically this could be accomplished in an external script by calling cloudns_api.sh listzones followed by cloudns_api.sh dumpzone for every zone. However, dumpzone itself uses listzones to determine if the specified zone is a valid zone in the account. This means that calling dumpzone 20 times also calls listzones 20 times! That's a waste of API calls, particular in this case where we know the zone names are valid.

To fix this, I split the dump_zone function into two separate functions: dump_zone that does all the validation, and dump_zone_impl that actually does the zone export. dump_all_zones uses dump_zone_impl directly, as it does not need to perform any of the validation.

Copy link
Owner

@tokiwinter tokiwinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly, sorry this has taken an age for me to get to.

All good apart from one comment.

Thanks

fi

local OUTPUT_DIR="$1"
mkdir -p $OUTPUT_DIR
Copy link
Owner

@tokiwinter tokiwinter Oct 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please do something like:

if ! mkdir -p ${OUTPUT_DIR} >/dev/null 2>&1; then
  print_error "Unable to create output directory ${OUTPUT_DIR}"
  exit 1
fi

otherwise you'll end up with an unhandled error, best case a bunch of output files in the current directory, worst case a bunch of errors about not being able to write to some path.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll do that when I get some free time.

@Daniel15
Copy link
Contributor Author

It's been a while, but I finally got around to updating this. Now it checks the return value of mkdir:

$ ./cloudns_api.sh dumpallzones /invalid-directory
Sun Apr 15 16:55:55 DST 2018: Error: Unable to create output directory /invalid-directory

Otherwise, when running normally, it outputs the name of each zone as it's dumped:

$ ./cloudns_api.sh dumpallzones /tmp/dns-zones
- d.sb
- dan.cx
- dan.net.au
...

@tokiwinter tokiwinter merged commit 64e73c9 into tokiwinter:master Jun 18, 2018
@Daniel15 Daniel15 deleted the dumpall branch July 11, 2019 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants