@@ -1789,7 +1789,7 @@ def is_controller(cls):
17891789 return cls ._is_mounted (DATABASE_PATH )
17901790
17911791 @classmethod
1792- def database_backup_age (cls ):
1792+ def get_database_backup_age (cls ):
17931793 """
17941794 Return the latest backup age in seconds.
17951795 If not called on the Controller, since backups are not available,
@@ -1817,17 +1817,17 @@ def database_invalidation(cls):
18171817 for directory in (DATABASE_BACKUP_DIR_MAIN , DATABASE_BACKUP_DIR_SPARE ):
18181818 valid_backup_count = 0
18191819 # Validate file and apply retention
1820- for database_backup_file , _ in cls ._get_sorted_database_backup (directory ):
1820+ for database_backup_path , _ in cls ._get_sorted_database_backup (directory ):
18211821 try :
1822- cls ._check_database_backup (database_backup_file )
1822+ cls ._check_database_backup (database_backup_path )
18231823 valid_backup_count += 1
18241824 if valid_backup_count < DATABASE_BACKUP_RETENTION :
18251825 continue
18261826 except LinstorDatabaseBackupError as error :
1827- util .SMlog (f"[database_backup] Check failed `{ error } ` [{ database_backup_file } ]" ,
1827+ util .SMlog (f"[database_backup] Check failed `{ error } ` [{ database_backup_path } ]" ,
18281828 priority = util .LOG_ERR )
18291829 with contextlib .suppress (OSError ):
1830- os .unlink (database_backup_file )
1830+ os .unlink (database_backup_path )
18311831
18321832 @classmethod
18331833 def get_all_group_names (cls , base_name ):
@@ -2707,7 +2707,7 @@ def _get_volume_properties(self, volume_uuid):
27072707 return properties
27082708
27092709 @classmethod
2710- def _list_database_backup (cls , database_backup_dir ):
2710+ def _list_database_backups (cls , database_backup_dir ):
27112711 """
27122712 List all visible backup files in database_backup_dir.
27132713 DATABASE_BACKUP_DIR_MAIN is only available on the Linstor Controller.
@@ -2727,7 +2727,7 @@ def _get_sorted_database_backup(cls, database_backup_dir):
27272727 Return list of backups in database_backup_dir, alongside their creation date.
27282728 Sorted by date from the more recent to the older one.
27292729 """
2730- return sorted (cls ._list_database_backup (database_backup_dir ),
2730+ return sorted (cls ._list_database_backups (database_backup_dir ),
27312731 reverse = True ,
27322732 key = lambda p : p [1 ])
27332733
@@ -2737,28 +2737,31 @@ def _get_latest_database_backup(cls):
27372737 Return the latest backup in DATABASE_BACKUP_DIR_MAIN, and its creation date.
27382738 Returns (None, timestamp(0)) when none are found.
27392739 None will be found if it is not called on the Linstor Controller.
2740- (cf _list_database_backup )
2740+ (cf _list_database_backups )
27412741 """
2742- return max (cls ._list_database_backup (DATABASE_BACKUP_DIR_MAIN ),
2742+ return max (cls ._list_database_backups (DATABASE_BACKUP_DIR_MAIN ),
27432743 default = (None , datetime .fromtimestamp (0 )),
27442744 key = lambda p : p [1 ])
27452745
27462746 @classmethod
2747- def _check_database_backup (cls , database_backup_file ):
2747+ def _check_database_backup (cls , database_backup_path ):
27482748 """
27492749 Make some validation of a database backup zip-file.
27502750 Check its a valid zipfile, and CRC-test its content.
27512751 Check it contains a non-empty linstordb.mv.db file.
27522752 Always raises a LinstorDatabaseBackupError if checks failed.
27532753 """
27542754 try :
2755- with zipfile .ZipFile (database_backup_file , mode = "r" ) as archive :
2755+ with zipfile .ZipFile (database_backup_path , mode = "r" ) as archive :
27562756 if archive .testzip () is not None :
27572757 raise LinstorDatabaseBackupError ("zip archive CRC failed" )
2758- linstordb = [f for f in archive .filelist if f .filename == "linstordb.mv.db" ]
2758+ linstordb = next ((
2759+ f
2760+ for f in archive .filelist
2761+ if f .filename == "linstordb.mv.db"
2762+ ), None )
27592763 if not linstordb :
27602764 raise LinstorDatabaseBackupError ("cannot find linstordb.mv.db" )
2761- linstordb = linstordb [0 ]
27622765 if linstordb .file_size == 0 :
27632766 raise LinstorDatabaseBackupError ("linstordb.mv.db is empty" )
27642767 except (FileNotFoundError , zipfile .BadZipFile , zipfile .LargeZipFile ) as e :
0 commit comments