Skip to content

Commit f139aed

Browse files
committed
Check if Include folders/files do exists (in case they are removed)
Solution b) when start taking a snapshot the include list should be checked of existence first and warn about missings. reference: bit-team#1586
1 parent 4b27c01 commit f139aed

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

common/backintime.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848

4949
parsers = {}
5050

51+
def warningOnTakeSnapshot(config):
52+
hasMissing, missing = snapshots.hasMissing(config.include())
53+
if hasMissing:
54+
msgMissing = ', '.join(missing)
55+
msg = f'{_("The following folders are missing")}: {msgMissing}'
56+
logger.warning(msg)
57+
return True
58+
5159
def takeSnapshotAsync(cfg, checksum = False):
5260
"""
5361
Fork a new backintime process with 'backup' command which will
@@ -56,6 +64,7 @@ def takeSnapshotAsync(cfg, checksum = False):
5664
Args:
5765
cfg (config.Config): config that should be used
5866
"""
67+
warningOnTakeSnapshot(cfg)
5968
cmd = []
6069
if cfg.ioniceOnUser():
6170
cmd.extend(('ionice', '-c2', '-n7'))
@@ -94,6 +103,7 @@ def takeSnapshot(cfg, force = True):
94103
Returns:
95104
bool: ``True`` if there was an error
96105
"""
106+
warningOnTakeSnapshot(cfg)
97107
tools.envLoad(cfg.cronEnvFile())
98108
ret = snapshots.Snapshots(cfg).backup(force)
99109
return ret

common/po/pt_BR.po

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,14 @@ msgstr "AVISO"
17241724
msgid "Exclude {path} from future snapshots?"
17251725
msgstr "Excluir {path} de snapshots futuros?"
17261726

1727+
#: qt/app.py:1189
1728+
msgid "The following folders are missing"
1729+
msgstr "As seguintes pastas estão faltando"
1730+
1731+
#: qt/app.py:1189
1732+
msgid "Do you want to proceed?"
1733+
msgstr "Deseja prosseguir?"
1734+
17271735
#~ msgid " and add your user to group 'fuse'"
17281736
#~ msgstr " e adicionar seu usuário para grupo 'fuse'"
17291737

common/snapshots.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,6 +3104,25 @@ def lastSnapshot(cfg):
31043104
return sids[0]
31053105

31063106

3107+
def hasMissing(included):
3108+
"""
3109+
Check if there are missing files or folders in a snapshot.
3110+
3111+
Args:
3112+
included (list): list of tuples (item, info)
3113+
3114+
Returns:
3115+
tuple: (bool, str) where bool is ``True`` if there are
3116+
missing files or folders and str is a message
3117+
describing the missing files or folders
3118+
"""
3119+
notFound = []
3120+
for path, info in included:
3121+
if not os.path.exists(path):
3122+
notFound.append(path)
3123+
return bool(notFound), notFound
3124+
3125+
31073126
if __name__ == '__main__':
31083127
config = config.Config()
31093128
snapshots = Snapshots(config)

qt/app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,11 +1182,26 @@ def updateTimeLine(self, refreshSnapshotsList = True):
11821182
item = self.timeLine.addSnapshot(sid)
11831183
self.timeLine.checkSelection()
11841184

1185+
def validateOnTakeSnapshot(self):
1186+
hasMissing, missing = snapshots.hasMissing(self.config.include())
1187+
if hasMissing:
1188+
msgMissing = '\n'.join(missing)
1189+
msg = f'{_("The following folders are missing")}:\n\n{msgMissing}\n\n{_("Do you want to proceed?")}'
1190+
answer = messagebox.warningYesNo(self, msg)
1191+
return answer == QMessageBox.StandardButton.Yes
1192+
return True
1193+
11851194
def btnTakeSnapshotClicked(self):
1195+
proceed = self.validateOnTakeSnapshot()
1196+
if not proceed:
1197+
return
11861198
backintime.takeSnapshotAsync(self.config)
11871199
self.updateTakeSnapshot(True)
11881200

11891201
def btnTakeSnapshotChecksumClicked(self):
1202+
proceed = self.validateOnTakeSnapshot()
1203+
if not proceed:
1204+
return
11901205
backintime.takeSnapshotAsync(self.config, checksum = True)
11911206
self.updateTakeSnapshot(True)
11921207

0 commit comments

Comments
 (0)