netcmd: Re-create default site for backup-restore (if missing)
commitdfc07455c2a31988012d6369107bf44efd0f8354
authorTim Beale <timbeale@catalyst.net.nz>
Tue, 18 Sep 2018 02:54:51 +0000 (18 14:54 +1200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 5 Nov 2018 11:44:29 +0000 (5 12:44 +0100)
tree212c1b02077e376599c9ec47bc3877a208f49e0d
parentc077dfaa6066ea0131ff50e514759fbdbba311cb
netcmd: Re-create default site for backup-restore (if missing)

Normally when a new DC joins a domain, samba-tool works out the new
DC's site automatically. However, it does this by querying the existing
DC using CLDAP. In the restore case, there is no DC running. We could
still query the DB on disk and work out the correct site based on the
new DC's IP, however:
- comparing between the CN=Subnet DNs and an IP-address string seems
  like it'd be non-trivial to write, and
- in the lab-domain rename case, chances are the user will want a
  completely different subnet to what's already in the DB.

The restore command now has a --site option so the user can specify an
appropriate site for the restored DC. This patch makes the restore
command work by default (i.e. without a --site option) even if the
default Default-First-Site-Name doesn't exist. Basically the solution is
to just check Default-First-Site-Name exists and create it if it
doesn't. As the recommended workflow is to use the restored DC as a
temporary seed that you'll later throw away, this approach seems
acceptable. Subsequent DCs will then be joined to the running restored
DC, so an appropriate site will be determined using CLDAP. The only
side-effect is potentially an extra Site object.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13621

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit ce57a800c9bed7e6876cdc0baf3a2d5fdc879ecf)
python/samba/netcmd/domain_backup.py