Opam repository broken

There were approx. 10 compilers installed and related packages in the opam repository of a host.
It has been “broken” for unknown reason so the following message appeared:

$ opam switch list
[ERROR] Opam has not been initialised, please run `opam init'

The suggested command installed a new compiler:

$ opam init
No configuration file found, using built-in defaults.
...
<><> Creating initial switch 'default' (invariant ["ocaml" {>= "4.05.0"}] - initially with ocaml-base-compiler) 

… but all the previous configuration became invisible before it was even completely installed:

$ opam switch list 
#  switch   compiler  description
   default            default
[NOTE] No switch is currently set, you should use 'opam switch <switch>' to set an active switch

Luckily, the previous ‘~/.opam’ directory was saved as '~/.opam ’ (with one trailing space - weird naming…).

How can I get my previous configuration back?
Can I safely delete the new dir and rename the old one from '~/.opam ’ to ‘~/.opam’?

I’m impressed by the size of the ~/.opam directory (120 GB for approx. 10 compilers&packages).
Are packages shared between theses configurations or duplicated?..

Side question: I’m tired of entering CLI opam commands with sometimes weird messages and surprising behaviors. Is there an OCaml API that makes possible to do opam management via a program?

After a full back up of the system, I could do:

mv '~/.opam' '~/.opam_5.0.0' && mv '~/.opam ' '~/.opam'

… and could see my repository with all OCaml compilers and related packages wit opam switch list.

BUT, (short story) the process of opam init building a 5.0.0 compiler configuration was paused and it didn’t want to be killed, so I put it on fg and ctrl-z, but not fast enough. And the opam configuration was broken again.
I reinstalled a new compiler.
NOW, I have in ~/.opam my previous stuff and a new compiler configuration installed with ONLY that new config visible.

I tried various opam init --xxx commands without success.

Finally, my question is:
How to restore an opam state from a set of valid compiler configurations (my previous stuff forgotten by opam during this accident)?