Skip to content

Commit

Permalink
Check if Include folders/files do exists (in case they are removed)
Browse files Browse the repository at this point in the history
Solution b) when start taking a snapshot the include list should be checked of existence first and warn about missings.

reference: bit-team#1586
  • Loading branch information
rafaelhdr committed May 9, 2024
1 parent 4b27c01 commit f6bf5bc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Back In Time

Version 1.4.4-dev (development of upcoming release)
* Fix bug: Check if Include folders/files do exists (in case they are removed) (1586) (@rafaelhdr)
* Feature: Support SSH proxy (jump) host (#1688) (@cgrinham, Christie Grinham)
* Removed: Context menu in LogViewDialog (#1578)
* Refactor: Replace Config.user() with getpass.getuser() (#1694)
Expand Down
10 changes: 10 additions & 0 deletions common/backintime.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@

parsers = {}

def warningOnTakeSnapshot(config):
hasMissing, missing = snapshots.hasMissing(config.include())
if hasMissing:
msgMissing = ', '.join(missing)
msg = f'{_("The following folders are missing")}: {msgMissing}'
logger.warning(msg)
return True

def takeSnapshotAsync(cfg, checksum = False):
"""
Fork a new backintime process with 'backup' command which will
Expand All @@ -56,6 +64,7 @@ def takeSnapshotAsync(cfg, checksum = False):
Args:
cfg (config.Config): config that should be used
"""
warningOnTakeSnapshot(cfg)
cmd = []
if cfg.ioniceOnUser():
cmd.extend(('ionice', '-c2', '-n7'))
Expand Down Expand Up @@ -94,6 +103,7 @@ def takeSnapshot(cfg, force = True):
Returns:
bool: ``True`` if there was an error
"""
warningOnTakeSnapshot(cfg)
tools.envLoad(cfg.cronEnvFile())
ret = snapshots.Snapshots(cfg).backup(force)
return ret
Expand Down
8 changes: 8 additions & 0 deletions common/po/pt_BR.po
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,14 @@ msgstr "AVISO"
msgid "Exclude {path} from future snapshots?"
msgstr "Excluir {path} de snapshots futuros?"

#: qt/app.py:1189
msgid "The following folders are missing"
msgstr "As seguintes pastas estão faltando"

#: qt/app.py:1189
msgid "Do you want to proceed?"
msgstr "Deseja prosseguir?"

#~ msgid " and add your user to group 'fuse'"
#~ msgstr " e adicionar seu usuário para grupo 'fuse'"

Expand Down
19 changes: 19 additions & 0 deletions common/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3104,6 +3104,25 @@ def lastSnapshot(cfg):
return sids[0]


def hasMissing(included):
"""
Check if there are missing files or folders in a snapshot.
Args:
included (list): list of tuples (item, info)
Returns:
tuple: (bool, str) where bool is ``True`` if there are
missing files or folders and str is a message
describing the missing files or folders
"""
notFound = []
for path, info in included:
if not os.path.exists(path):
notFound.append(path)
return bool(notFound), notFound


if __name__ == '__main__':
config = config.Config()
snapshots = Snapshots(config)
Expand Down
15 changes: 15 additions & 0 deletions qt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,11 +1182,26 @@ def updateTimeLine(self, refreshSnapshotsList = True):
item = self.timeLine.addSnapshot(sid)
self.timeLine.checkSelection()

def validateOnTakeSnapshot(self):
hasMissing, missing = snapshots.hasMissing(self.config.include())
if hasMissing:
msgMissing = '\n'.join(missing)
msg = f'{_("The following folders are missing")}:\n\n{msgMissing}\n\n{_("Do you want to proceed?")}'
answer = messagebox.warningYesNo(self, msg)
return answer == QMessageBox.StandardButton.Yes
return True

def btnTakeSnapshotClicked(self):
proceed = self.validateOnTakeSnapshot()
if not proceed:
return
backintime.takeSnapshotAsync(self.config)
self.updateTakeSnapshot(True)

def btnTakeSnapshotChecksumClicked(self):
proceed = self.validateOnTakeSnapshot()
if not proceed:
return
backintime.takeSnapshotAsync(self.config, checksum = True)
self.updateTakeSnapshot(True)

Expand Down

0 comments on commit f6bf5bc

Please sign in to comment.