@@ -456,13 +456,35 @@ def _save_index(self) -> None:
456456 self ._index .model_dump_json (indent = 4 ).encode ("utf-8" ),
457457 )
458458
459+ def _legacy_storage_migration_message (
460+ self , backup_path : Path , ert_version_to_use : str
461+ ) -> str :
462+ return dedent (
463+ f"""
464+ Detected outdated storage, which is no longer supported
465+ by ERT. Its contents are copied to:
466+
467+ { backup_path }
468+
469+ In order to migrate this storage, do the following:
470+
471+ (1) with ert version <= { ert_version_to_use } , open up
472+ the same ert config with: ENSPATH={ backup_path }
473+
474+ (2) with current ert version, open up the same storage again.
475+ The contents of the storage should now be up-to-date, and you may
476+ copy the ensembles and experiments into the original folder @
477+ { self .path } .
478+
479+ This is not guaranteed to work. Other than setting the custom
480+ ENSPATH, the ERT config should ideally be the same as it was
481+ when the old storage was created.
482+ """
483+ )
484+
459485 @require_write
460486 def _migrate (self , version : int ) -> None :
461487 from .migration import ( # noqa: PLC0415
462- to2 ,
463- to3 ,
464- to4 ,
465- to5 ,
466488 to6 ,
467489 to7 ,
468490 to8 ,
@@ -489,59 +511,36 @@ def _migrate(self, version: int) -> None:
489511 self ._index = self ._load_index ()
490512
491513 logger .info ("Blockfs storage backed up" )
492- print (
493- dedent (
494- f"""
495- Detected outdated storage (blockfs), which is no longer supported
496- by ERT. Its contents are copied to:
497-
498- { self .path / "_ert_block_storage_backup" }
499-
500- In order to migrate this storage, do the following:
501-
502- (1) with ert version <= 10.3.*, open up the same ert config with:
503- ENSPATH={ self .path / "_ert_block_storage_backup" }
514+ print (self ._legacy_storage_migration_message (bkup_path , "10.3.*" ))
515+ return None
516+ elif version < 5 :
517+ bkup_path = self .path / "_storage_backup_lt_5"
518+ dirs = set (os .listdir (self .path )) - {"storage.lock" }
519+ os .mkdir (bkup_path )
520+ for directory in dirs :
521+ shutil .move (self .path / directory , bkup_path / directory )
504522
505- (2) with current ert version, open up the same storage again.
506- The contents of the storage should now be up-to-date, and you may
507- copy the ensembles and experiments into the original folder @
508- { self .path } .
523+ self ._index = self ._load_index ()
509524
510- This is not guaranteed to work. Other than setting the custom
511- ENSPATH, the ERT config should ideally be the same as it was
512- when the old blockfs storage was created.
513- """
514- )
515- )
525+ logger .info ("storage backed up for version less than 6" )
526+ print (self ._legacy_storage_migration_message (bkup_path , "14.6.*" ))
516527 return None
517-
518528 elif version < _LOCAL_STORAGE_VERSION :
519- migrations = list (
520- enumerate (
521- [
522- to2 ,
523- to3 ,
524- to4 ,
525- to5 ,
526- to6 ,
527- to7 ,
528- to8 ,
529- to9 ,
530- to10 ,
531- to11 ,
532- to12 ,
533- to13 ,
534- ],
535- start = 1 ,
536- )
537- )
538- for from_version , migration in migrations [version - 1 :]:
539- print (f"* Updating storage to version: { from_version + 1 } " )
540- migration .migrate (self .path )
529+ migrations = {
530+ 5 : to6 ,
531+ 6 : to7 ,
532+ 7 : to8 ,
533+ 8 : to9 ,
534+ 9 : to10 ,
535+ 10 : to11 ,
536+ 11 : to12 ,
537+ 12 : to13 ,
538+ }
539+ for from_version in range (version , _LOCAL_STORAGE_VERSION ):
540+ migrations [from_version ].migrate (self .path )
541541 self ._add_migration_information (
542- from_version , from_version + 1 , migration .info
542+ from_version , from_version + 1 , migrations [ from_version ] .info
543543 )
544-
545544 except Exception as e :
546545 logger .error (
547546 f"Migrating storage at { self .path } failed with: { e } " , stack_info = True
0 commit comments