@@ -1780,7 +1780,7 @@ def database_backup_age(cls):
17801780 If not called on the Controller, since backups are not available,
17811781 returns a huge value (a timestamp of now).
17821782 """
1783- return (datetime .now () - cls ._get_latest_database_backup ()).total_seconds ()
1783+ return (datetime .now () - cls ._get_latest_database_backup ()[ 1 ] ).total_seconds ()
17841784
17851785 def database_backup (self , name = "" ):
17861786 # Create new backup
@@ -2672,27 +2672,49 @@ def _get_volume_properties(self, volume_uuid):
26722672
26732673 @classmethod
26742674 def _list_database_backup (cls , database_backup_dir ):
2675+ """
2676+ List all visible backup files in database_backup_dir.
2677+ DATABASE_BACKUP_DIR_MAIN is only available on the Linstor Controller.
2678+ DATABASE_BACKUP_DIR_SPARE will list backups previously made when the Host was the Linstor Controller.
2679+ This may not be useful information if it is not the Controller anymore.
2680+ """
26752681 for path in database_backup_dir .glob (DATABASE_BACKUP_NAME_FORMAT .format (
2676- "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" ):
2682+ "[0-9]" * 8 + "_" + " [0-9]" * 6 , "*" ) + ".zip" ):
26772683 try :
26782684 yield path , datetime .strptime (path .name .split ("-" )[1 ], DATABASE_BACKUP_DATE_FORMAT )
26792685 except (ValueError , IndexError ):
26802686 continue
26812687
26822688 @classmethod
26832689 def _get_sorted_database_backup (cls , database_backup_dir ):
2690+ """
2691+ Return list of backups in database_backup_dir, alongside their creation date.
2692+ Sorted by date from the more recent to the older one.
2693+ """
26842694 return sorted (cls ._list_database_backup (database_backup_dir ),
26852695 reverse = True ,
26862696 key = lambda p : p [1 ])
26872697
26882698 @classmethod
26892699 def _get_latest_database_backup (cls ):
2700+ """
2701+ Return the latest backup in DATABASE_BACKUP_DIR_MAIN, and its creation date.
2702+ Returns (None, timestamp(0)) when none are found.
2703+ None will be found if it is not called on the Linstor Controller.
2704+ (cf _list_database_backup)
2705+ """
26902706 return max (cls ._list_database_backup (DATABASE_BACKUP_DIR_MAIN ),
26912707 default = (None , datetime .fromtimestamp (0 )),
26922708 key = lambda p : p [1 ])
26932709
26942710 @classmethod
26952711 def _check_database_backup (cls , database_backup_file ):
2712+ """
2713+ Make some validation of a database backup zip-file.
2714+ Check its a valid zipfile, and CRC-test its content.
2715+ Check it contains a non-empty linstordb.mv.db file.
2716+ Always raises a LinstorDatabaseBackupError if checks failed.
2717+ """
26962718 try :
26972719 with zipfile .ZipFile (database_backup_file , mode = "r" ) as archive :
26982720 if archive .testzip () is not None :
@@ -2703,8 +2725,6 @@ def _check_database_backup(cls, database_backup_file):
27032725 linstordb = linstordb [0 ]
27042726 if linstordb .file_size == 0 :
27052727 raise LinstorDatabaseBackupError ("linstordb.mv.db is empty" )
2706- except LinstorDatabaseBackupError :
2707- raise
27082728 except (FileNotFoundError , zipfile .BadZipFile , zipfile .LargeZipFile ) as e :
27092729 raise LinstorDatabaseBackupError (e ) from e
27102730
0 commit comments