copied from https://bitbucket.org/truls/ncctl-dbtr (for convenience, since I no longer use bitbucket)