diff options
author | Tim Beale <timbeale@catalyst.net.nz> | 2018-11-08 16:41:52 +1300 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2018-11-20 01:33:33 +0100 |
commit | 6e5ebbfb65344661ae4bcee02abc9143fb61bb84 (patch) | |
tree | f894e0f0666eea17c3075d3e03985b9f8542344c /python | |
parent | 65e7476a87b4d5f5c4f98ac08e17621dc7a70a8d (diff) | |
download | samba-6e5ebbfb65344661ae4bcee02abc9143fb61bb84.tar.gz |
netcmd: Add backupType marker to backed-up DB
We are starting to hit restore cases that are only applicable to a
particular type of backup. We already had a marker to differentiate
renames, but differentiating offline backups would also be useful.
Note that this raises a slight compatibility issue for backups created
on v4.9, as the marker won't exist. However, it's only offline backups
we will use this marker for (at the moment), and this option doesn't
exist on v4.9, so there's no problem.
Removing the markers has been refactored out into a separate function to
handle the optional presence of the new marker.
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/netcmd/domain_backup.py | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/python/samba/netcmd/domain_backup.py b/python/samba/netcmd/domain_backup.py index 5e7435645c3..4ba09cc15ec 100644 --- a/python/samba/netcmd/domain_backup.py +++ b/python/samba/netcmd/domain_backup.py @@ -261,6 +261,7 @@ class cmd_domain_backup_online(samba.netcmd.Command): time_str = get_timestamp() add_backup_marker(samdb, "backupDate", time_str) add_backup_marker(samdb, "sidForRestore", new_sid) + add_backup_marker(samdb, "backupType", "online") # ensure the admin user always has a password set (same as provision) if no_secrets: @@ -380,6 +381,25 @@ class cmd_domain_backup_restore(cmd_fsmo_seize): return sitename + def remove_backup_markers(self, samdb): + """Remove DB markers added by the backup process""" + + # check what markers we need to remove (this may vary) + markers = ['sidForRestore', 'backupRename', 'backupDate', 'backupType'] + res = samdb.search(base=ldb.Dn(samdb, "@SAMBA_DSDB"), + scope=ldb.SCOPE_BASE, + attrs=markers) + + # remove any markers that exist in the DB + m = ldb.Message() + m.dn = ldb.Dn(samdb, "@SAMBA_DSDB") + + for attr in markers: + if attr in res[0]: + m[attr] = ldb.MessageElement([], ldb.FLAG_MOD_DELETE, attr) + + samdb.modify(m) + def run(self, sambaopts=None, credopts=None, backup_file=None, targetdir=None, newservername=None, host_ip=None, host_ip6=None, site=None): @@ -553,16 +573,7 @@ class cmd_domain_backup_restore(cmd_fsmo_seize): self.fix_old_dc_references(samdb) # Remove DB markers added by the backup process - m = ldb.Message() - m.dn = ldb.Dn(samdb, "@SAMBA_DSDB") - m["backupDate"] = ldb.MessageElement([], ldb.FLAG_MOD_DELETE, - "backupDate") - m["sidForRestore"] = ldb.MessageElement([], ldb.FLAG_MOD_DELETE, - "sidForRestore") - if is_rename: - m["backupRename"] = ldb.MessageElement([], ldb.FLAG_MOD_DELETE, - "backupRename") - samdb.modify(m) + self.remove_backup_markers(samdb) logger.info("Backup file successfully restored to %s" % targetdir) logger.info("Please check the smb.conf settings are correct before " @@ -790,6 +801,7 @@ class cmd_domain_backup_rename(samba.netcmd.Command): add_backup_marker(samdb, "backupDate", time_str) add_backup_marker(samdb, "sidForRestore", new_sid) add_backup_marker(samdb, "backupRename", old_realm) + add_backup_marker(samdb, "backupType", "rename") # fix up the DNS objects that are using the old dnsRoot value self.update_dns_root(logger, samdb, old_realm, delete_old_dns) @@ -992,6 +1004,7 @@ class cmd_domain_backup_offline(samba.netcmd.Command): time_str = get_timestamp() add_backup_marker(samdb, "backupDate", time_str) add_backup_marker(samdb, "sidForRestore", sid) + add_backup_marker(samdb, "backupType", "offline") # Now handle all the LDB and TDB files that are not linked to # anything else. Use transactions for LDBs. |