mirror of
https://github.com/samba-team/samba.git
synced 2025-03-20 22:50:26 +03:00
netcmd: Improve domain backup targetdir checks
+ Added check that specified targetdir is actually a directory (if it exists) + Deleted a redundant 'Creating targetdir' check that would never be hit + Move code into a separate function so we can reuse it for offline backups (which take a different set of parameters, but still have a targetdir) Signed-off-by: Tim Beale <timbeale@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz> (cherry picked from commit 4f532cc177cd1e95d8ccf8e69f50b315354df34c) Backported to v4.9 for: BUG: https://bugzilla.samba.org/show_bug.cgi?id=13566
This commit is contained in:
parent
6244e6ab6b
commit
ec47551138
@ -139,6 +139,17 @@ def add_backup_marker(samdb, marker, value):
|
||||
samdb.modify(m)
|
||||
|
||||
|
||||
def check_targetdir(logger, targetdir):
|
||||
if targetdir is None:
|
||||
raise CommandError('Target directory required')
|
||||
|
||||
if not os.path.exists(targetdir):
|
||||
logger.info('Creating targetdir %s...' % targetdir)
|
||||
os.makedirs(targetdir)
|
||||
elif not os.path.isdir(targetdir):
|
||||
raise CommandError("%s is not a directory" % targetdir)
|
||||
|
||||
|
||||
def check_online_backup_args(logger, credopts, server, targetdir):
|
||||
# Make sure we have all the required args.
|
||||
u_p = {'user': credopts.creds.get_username(),
|
||||
@ -147,12 +158,8 @@ def check_online_backup_args(logger, credopts, server, targetdir):
|
||||
raise CommandError("Creds required.")
|
||||
if server is None:
|
||||
raise CommandError('Server required')
|
||||
if targetdir is None:
|
||||
raise CommandError('Target directory required')
|
||||
|
||||
if not os.path.exists(targetdir):
|
||||
logger.info('Creating targetdir %s...' % targetdir)
|
||||
os.makedirs(targetdir)
|
||||
check_targetdir(logger, targetdir)
|
||||
|
||||
|
||||
# For '--no-secrets' backups, this sets the Administrator user's password to a
|
||||
@ -211,10 +218,6 @@ class cmd_domain_backup_online(samba.netcmd.Command):
|
||||
lp = sambaopts.get_loadparm()
|
||||
creds = credopts.get_credentials(lp)
|
||||
|
||||
if not os.path.exists(targetdir):
|
||||
logger.info('Creating targetdir %s...' % targetdir)
|
||||
os.makedirs(targetdir)
|
||||
|
||||
tmpdir = tempfile.mkdtemp(dir=targetdir)
|
||||
|
||||
# Run a clone join on the remote
|
||||
|
Loading…
x
Reference in New Issue
Block a user