Skip to content

Commit

Permalink
add mail notification about empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
outdoorbits committed Oct 5, 2024
1 parent c3b6148 commit 69f8ef3
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 20 deletions.
21 changes: 14 additions & 7 deletions scripts/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,18 +683,25 @@ def backup(self):
# Remove empty files (maybe can result from disconnection of a source-device)
if self.TargetDevice.mountable and self.TargetDevice.FilesStayInPlace:
SourceCommand = ['find', os.path.join(self.TargetDevice.MountPoint, self.TargetDevice.CloudBaseDir, self.SourceDevice.SubPathAtTarget), '-type', 'f','-size', '0']
FilterCommand = ['wc', '-l']

emptyFiles = []
try:
progress.CountProgress -= int(lib_common.pipe(SourceCommand, FilterCommand).decode())
emptyFilesRaw = subprocess.check_output(SourceCommand).decode().strip()
if emptyFilesRaw:
emptyFiles= emptyFilesRaw.split('\n')
except:
pass

SourceCommand += ['-delete']
try:
subprocess.run(SourceCommand)
except:
self.__log.message(f"Error: '{' '.join(SourceCommand)}'")
if len(emptyFiles) > 0:
emptyFilesString = '|#|'.join(emptyFiles)
self.__reporter.add_error(Error=f'Empty files Err.:{emptyFilesString}')
progress.CountProgress -= len(emptyFiles)

SourceCommand += ['-delete']
try:
subprocess.run(SourceCommand)
except:
self.__log.message(f"Error: '{' '.join(SourceCommand)}'")

# Re-calculate FilesToProcess
FilesToProcessPost = FilesToProcess - progress.CountProgress
Expand Down
3 changes: 2 additions & 1 deletion scripts/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@
"no_backup": "Fehler: Kein Backup durchgeführt!",
"remount_device_failed": "Remount fehlgeschlagen!",
"removed_source": "Übertragene Dateien wurden von der Quelle gelöscht. (falls möglich)",
"files_validation_failed": "Dateien konnten bei der Validierung auf dem Zieldatenträger nicht gefunden werden."
"files_validation_failed": "Dateien konnten bei der Validierung auf dem Zieldatenträger nicht gefunden werden.",
"empty_files": "Die folgenden Dateien wurden leer empfangen und vom Zielspeicher gelöscht. Bitte prüfen Sie, ob sie auch auf der Quelle leer sind. Falls ja, löschen Sie sie bitte dort, um zukünftige Fehlermeldungen zu vermeiden.<br>Leere Dateien:"
},
"try": "Versuch",
"checking_old_files": "abgleichen",
Expand Down
3 changes: 2 additions & 1 deletion scripts/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"no_backup": "Error: No backup performed!",
"remount_device_failed": "Remount failed!",
"removed_source": "Transferred files have been deleted from the source. (if possible)",
"files_validation_failed": "Files could not be found on the target disk during validation."
"files_validation_failed": "Files could not be found on the target disk during validation.",
"empty_files": "The following files were received empty and deleted from the destination storage. Please check if they are also empty on the source. If so, please delete them there to avoid future error messages.<br>Empty files:"
},
"storage_filesystem_short": "FS",
"exception": "Unknown error",
Expand Down
3 changes: 2 additions & 1 deletion scripts/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@
"no_backup": "Error: No se realizó ninguna copia de seguridad!",
"remount_device_failed": "¡El montaje falló!",
"removed_source": "Los archivos transferidos se han eliminado de la fuente. (si es posible)",
"files_validation_failed": "No se pudieron encontrar archivos en el disco de destino durante la validación."
"files_validation_failed": "No se pudieron encontrar archivos en el disco de destino durante la validación.",
"empty_files": "Los siguientes archivos se recibieron vacíos y se eliminaron del almacenamiento de destino. Compruebe si también están en blanco en la fuente. Si es así, elimínelo allí para evitar futuros mensajes de error.<br>Archivos vacíos:"
},
"try": "Intentar",
"checking_old_files": "comparando",
Expand Down
3 changes: 2 additions & 1 deletion scripts/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@
"no_backup": "Erreur: Aucune sauvegarde effectuée!",
"remount_device_failed": "Le remontage a échoué !",
"removed_source": "Les fichiers transférés ont été supprimés de la source. (si possible)",
"files_validation_failed": "Les dates ne correspondent pas à la validation auf dem Zieldatenträger nicht gefunden werden."
"files_validation_failed": "Les dates ne correspondent pas à la validation auf dem Zieldatenträger nicht gefunden werden.",
"empty_files": "Les fichiers suivants ont été reçus vides et supprimés du stockage de destination. Veuillez vérifier s'ils sont également vides sur la source. Si tel est le cas, veuillez le supprimer ici pour éviter de futurs messages d'erreur.<br>Fichiers vides:"
},
"try": "essayer",
"checking_old_files": "comparant",
Expand Down
23 changes: 15 additions & 8 deletions scripts/lib_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,11 @@ def __display_progress(self):
DisplayLine5="PGBAR=0"

# calculte remaining time
if self.CountProgress > 0:

if self.CountProgress > self.CountSkip:
TimeElapsed = lib_system.get_uptime_sec() - self.StartTime
TimeRemaining = TimeElapsed / (self.CountProgress - self.CountSkip if self.CountProgress > self.CountSkip else 1) * (self.FilesToProcess - self.CountProgress)
TimeRemaining = (self.FilesToProcess - self.CountProgress) * TimeElapsed / (self.CountProgress - self.CountSkip)
TimeRemainingFormatted = str(timedelta(seconds=TimeRemaining)).split('.')[0]
else:

self.CountProgress = 0
TimeRemainingFormatted = '?'

# DisplayLine4
Expand Down Expand Up @@ -295,15 +292,15 @@ def set_values(self, FilesToProcess=None, FilesProcessed=None, FilesCopied=None,
if not SyncReturnCode is None:
self.__BackupReports[self.__Folder][-1]['SyncReturnCode'] = SyncReturnCode

def add_synclog(self,SyncLog=''):
def add_synclog(self, SyncLog=''):
SyncLog = SyncLog.strip()
if self.__SyncLog and SyncLog:
self.__BackupReports[self.__Folder][-1]['SyncLogs'].append(SyncLog)

def add_result(self,Result=''):
def add_result(self, Result=''):
self.__BackupReports[self.__Folder][-1]['Results'].append(Result)

def add_error(self,Error=''):
def add_error(self, Error=''):
self.__BackupReports[self.__Folder][-1]['Errors'].append(Error)

def get_errors(self):
Expand Down Expand Up @@ -383,6 +380,16 @@ def prepare_mail(self):
if 'Exception' in Report['Errors']:
self.mail_content_HTML += f"\n <p style='{CSS_margins_left_1} {CSS_font_format_alert}'>{self.__lan.l('box_backup_mail_exception')} {Report['SyncReturnCode']} ({self.sync_return_code_decoder(Report['SyncReturnCode'])}).</p>"

if len([Error for Error in Report['Errors'] if Error.startswith('Empty files Err.:')]) > 0:
EmptyFiles = []
for Error in Report['Errors']:
if Error.startswith('Empty files Err.:'):
EmptyFiles += Error.split(':',1)[1].split('|#|')

EmptyFilesString = '</li>\n<li>'.join(EmptyFiles)
EmptyFilesString = f'\n<ul><li>{EmptyFilesString}</li></ul>'
self.mail_content_HTML += f"\n <p style='{CSS_margins_left_1}'>{self.__lan.l('box_backup_mail_empty_files')} {EmptyFilesString}</p>"

FilesCopiedAll = Report['FilesToProcess'] - Report['FilesToProcessPost'] if not Report['FilesToProcessPost'] is None else '?'
self.mail_content_HTML += f"\n <p style='{CSS_margins_left_1}'>{FilesCopiedAll} {self.__lan.l('box_backup_of')} {Report['FilesToProcess']} {self.__lan.l('box_backup_files_copied')}. ({Report['FilesCopied']} {self.__lan.l('box_backup_files_just_copied')})</p>"

Expand Down
3 changes: 2 additions & 1 deletion scripts/lib_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class debug(object):
def __init__(self):
self.debugbasetime=int(datetime.now().timestamp())

def d(self, debugstring):
def d(self, debugmessage):
debugstring = str(debugmessage)
debugstring = debugstring.strip()
Message = f"{int(datetime.now().timestamp()) - self.debugbasetime}\t{__name__}\t{debugstring}"
print(Message,file=sys.stderr)
Expand Down
1 change: 1 addition & 0 deletions scripts/lib_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def remove_HTML_tags(HTML):

replaceings = {
'<hr style="width:50%;">': ' *****',
'<li>': ' - ',
'&quot;': '"',
}

Expand Down

0 comments on commit 69f8ef3

Please sign in to comment.