mirror of
https://github.com/samba-team/samba.git
synced 2025-12-21 20:23:50 +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>
This commit is contained in:
@@ -139,6 +139,17 @@ def add_backup_marker(samdb, marker, value):
|
|||||||
samdb.modify(m)
|
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):
|
def check_online_backup_args(logger, credopts, server, targetdir):
|
||||||
# Make sure we have all the required args.
|
# Make sure we have all the required args.
|
||||||
u_p = {'user': credopts.creds.get_username(),
|
u_p = {'user': credopts.creds.get_username(),
|
||||||
@@ -147,12 +158,8 @@ def check_online_backup_args(logger, credopts, server, targetdir):
|
|||||||
raise CommandError("Creds required.")
|
raise CommandError("Creds required.")
|
||||||
if server is None:
|
if server is None:
|
||||||
raise CommandError('Server required')
|
raise CommandError('Server required')
|
||||||
if targetdir is None:
|
|
||||||
raise CommandError('Target directory required')
|
|
||||||
|
|
||||||
if not os.path.exists(targetdir):
|
check_targetdir(logger, targetdir)
|
||||||
logger.info('Creating targetdir %s...' % targetdir)
|
|
||||||
os.makedirs(targetdir)
|
|
||||||
|
|
||||||
|
|
||||||
# For '--no-secrets' backups, this sets the Administrator user's password to a
|
# 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()
|
lp = sambaopts.get_loadparm()
|
||||||
creds = credopts.get_credentials(lp)
|
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)
|
tmpdir = tempfile.mkdtemp(dir=targetdir)
|
||||||
|
|
||||||
# Run a clone join on the remote
|
# Run a clone join on the remote
|
||||||
|
|||||||
Reference in New Issue
Block a user