@@ -1801,7 +1801,7 @@ def database_backup_age(cls):
18011801 If not called on the Controller, since backups are not available,
18021802 returns a huge value (a timestamp of now).
18031803 """
1804- return (datetime .now () - cls ._get_latest_database_backup ()).total_seconds ()
1804+ return (datetime .now () - cls ._get_latest_database_backup ()[ 1 ] ).total_seconds ()
18051805
18061806 def database_backup (self , name = "" ):
18071807 # Create new backup
@@ -2714,27 +2714,49 @@ def _get_volume_properties(self, volume_uuid):
27142714
27152715 @classmethod
27162716 def _list_database_backup (cls , database_backup_dir ):
2717+ """
2718+ List all visible backup files in database_backup_dir.
2719+ DATABASE_BACKUP_DIR_MAIN is only available on the Linstor Controller.
2720+ DATABASE_BACKUP_DIR_SPARE will list backups previously made when the Host was the Linstor Controller.
2721+ This may not be useful information if it is not the Controller anymore.
2722+ """
27172723 for path in database_backup_dir .glob (DATABASE_BACKUP_NAME_FORMAT .format (
2718- "20 [0-9][0-9][01][0-9][0-3][0-9]_ [0-2][0-9][0-5][0-9][0-5][0-9]" , "*" ) + ".zip" ):
2724+ "[0-9]" * 8 + "_" + " [0-9]" * 6 , "*" ) + ".zip" ):
27192725 try :
27202726 yield path , datetime .strptime (path .name .split ("-" )[1 ], DATABASE_BACKUP_DATE_FORMAT )
27212727 except (ValueError , IndexError ):
27222728 continue
27232729
27242730 @classmethod
27252731 def _get_sorted_database_backup (cls , database_backup_dir ):
2732+ """
2733+ Return list of backups in database_backup_dir, alongside their creation date.
2734+ Sorted by date from the more recent to the older one.
2735+ """
27262736 return sorted (cls ._list_database_backup (database_backup_dir ),
27272737 reverse = True ,
27282738 key = lambda p : p [1 ])
27292739
27302740 @classmethod
27312741 def _get_latest_database_backup (cls ):
2742+ """
2743+ Return the latest backup in DATABASE_BACKUP_DIR_MAIN, and its creation date.
2744+ Returns (None, timestamp(0)) when none are found.
2745+ None will be found if it is not called on the Linstor Controller.
2746+ (cf _list_database_backup)
2747+ """
27322748 return max (cls ._list_database_backup (DATABASE_BACKUP_DIR_MAIN ),
27332749 default = (None , datetime .fromtimestamp (0 )),
27342750 key = lambda p : p [1 ])
27352751
27362752 @classmethod
27372753 def _check_database_backup (cls , database_backup_file ):
2754+ """
2755+ Make some validation of a database backup zip-file.
2756+ Check its a valid zipfile, and CRC-test its content.
2757+ Check it contains a non-empty linstordb.mv.db file.
2758+ Always raises a LinstorDatabaseBackupError if checks failed.
2759+ """
27382760 try :
27392761 with zipfile .ZipFile (database_backup_file , mode = "r" ) as archive :
27402762 if archive .testzip () is not None :
@@ -2745,8 +2767,6 @@ def _check_database_backup(cls, database_backup_file):
27452767 linstordb = linstordb [0 ]
27462768 if linstordb .file_size == 0 :
27472769 raise LinstorDatabaseBackupError ("linstordb.mv.db is empty" )
2748- except LinstorDatabaseBackupError :
2749- raise
27502770 except (FileNotFoundError , zipfile .BadZipFile , zipfile .LargeZipFile ) as e :
27512771 raise LinstorDatabaseBackupError (e ) from e
27522772
0 commit comments