Skip to content

Commit

Permalink
chore: Minor improvements in logging around canBackup function
Browse files Browse the repository at this point in the history
  • Loading branch information
buhtz committed Aug 24, 2024
1 parent 0beae11 commit 1e0079b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
8 changes: 5 additions & 3 deletions common/backintime.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,10 @@ def startApp(app_name='backintime'):
args = argParse(None)

# Name, Version, As Root, OS
msg = ''
for key, val in collect_minimal_diagnostics().items():
logger.debug(f'{key}: {val}')
msg = f'{msg}; {key}: {val}'
logger.debug(msg[2:])

# Add source path to $PATH environ if running from source
if tools.runningFromSource():
Expand Down Expand Up @@ -610,8 +612,8 @@ def join(args, subArgs):
for key
in filter(lambda key: args_dict[key] is not None, args_dict)
}
logger.debug(f'Used argument(s): {used_args}')
logger.debug(f'Unknown argument(s): {unknownArgs}')

logger.debug(f'Argument(s) used: {used_args}')

# Report unknown arguments but not if we run aliasParser next because we
# will parse again in there.
Expand Down
48 changes: 33 additions & 15 deletions common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,25 @@ def pid(self):
def host(self):
return socket.gethostname()

def snapshotsPath(self, profile_id = None, mode = None, tmp_mount = False):
def snapshotsPath(self, profile_id=None, mode=None, tmp_mount=False):
"""Return the snapshot path (backup destination).
"""
if mode is None:
mode = self.snapshotsMode(profile_id)

# If there are <mounttools> for this mode, then
# the path need to be mounted.
if self.SNAPSHOT_MODES[mode][0] == None:
#no mount needed
# No mount needed
#?Where to save snapshots in mode 'local'. This path must contain a
#?folderstructure like 'backintime/<HOST>/<USER>/<PROFILE_ID>';absolute path
return self.profileStrValue('snapshots.path', '', profile_id)

else:
#mode need to be mounted; return mountpoint
symlink = self.snapshotsSymlink(profile_id = profile_id, tmp_mount = tmp_mount)
# Mode need to be mounted; return mountpoint
symlink = self.snapshotsSymlink(
profile_id=profile_id, tmp_mount=tmp_mount)

return os.path.join(self._LOCAL_MOUNT_ROOT, symlink)

def snapshotsFullPath(self, profile_id = None):
Expand Down Expand Up @@ -942,10 +950,10 @@ def includeV4(self, profile_id = None):

return paths

def include(self, profile_id = None):
def include(self, profile_id=None):
#?Include this file or folder. <I> must be a counter starting with 1;absolute path::
#?Specify if \fIprofile<N>.snapshots.include.<I>.value\fR is a folder (0) or a file (1).;0|1;0
return self.profileListValue('snapshots.include', ('str:value', 'int:type'), [], profile_id)
return self.profileListValue(key='snapshots.include', type_key=('str:value', 'int:type'), default=[], profile_id=profile_id)

def setInclude(self, values, profile_id = None):
self.setProfileListValue('snapshots.include', ('str:value', 'int:type'), values, profile_id)
Expand Down Expand Up @@ -1538,27 +1546,37 @@ def preparePath(self, path):
path = path[: -1]
return path

def isConfigured(self, profile_id = None):
"""
Checks if the program is configured
"""
return bool(self.snapshotsPath(profile_id) and self.include(profile_id))
def isConfigured(self, profile_id=None):
"""Checks if the program is configured.
def canBackup(self, profile_id = None):
It is assumed as configured if a snapshot path (backup destination) is
and include files/directories (backup source) are given.
"""
Checks if snapshots_path exists
path = self.snapshotsPath(profile_id)
includes = self.include(profile_id)

if bool(path and includes):
return True
else:
logger.debug(f'Profile ({profile_id=}) is not configured because '
f'snapshot path is {bool(path)} and/or includes '
f'are {bool(includes)}.', self)
return False

def canBackup(self, profile_id=None):
"""Checks if snapshots_path exists.
"""
if not self.isConfigured(profile_id):
return False

path = self.snapshotsFullPath(profile_id)

if not os.path.exists(path):
logger.warning(f'Snapshot path does not exists: {path}', self)
return False

if not os.path.isdir(path):
# path exists, but is no dir: something's very wrong.
logger.error("%s is not a directory"%path, self)
logger.warning(f'Snapshot path is not a directory: {path}', self)
return False

return True
Expand Down
24 changes: 12 additions & 12 deletions common/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,25 +845,23 @@ def backup(self, force=False):
message=message,
timeout=30)

logger.warning(
'Cannot start snapshot yet: target directory '
'not accessible. Will retry each second in '
'the next 30 seconds. Please wait.')

counter = 0
for counter in range(0, 30):
logger.debug(
'Cannot start snapshot yet: target '
'directory not accessible. Waiting 1s.')

time.sleep(1)

if self.config.canBackup():
break

if counter != 0:
logger.info(
f'Waited {counter} seconds for target '
'directory to be available', self)

if not self.config.canBackup(profile_id):
logger.warning(
"Can't find snapshots folder!", self)
logger.error('Snapshots directory not '
'accessible. Tries stopped.',
self)
# Can't find snapshots directory (is it on a
# removable drive ?)
self.config.PLUGIN_MANAGER.error(3)
Expand All @@ -873,8 +871,10 @@ def backup(self, force=False):
sid = SID(now, self.config)

if sid.exists():
logger.warning(f'Snapshot path "{sid.path()}" '
'already exists', self)
logger.warning(
f'Snapshot directory "{sid.path()}" '
'already exists',
self)
# This snapshot already exists
self.config.PLUGIN_MANAGER.error(4, sid)

Expand Down

0 comments on commit 1e0079b

Please sign in to comment.