Restore DatasetImageLink in OMERO database

Hi all,
I accidentally deleted some DatasetImageLinks when using omero chown in the wrong way (i.e. omiting --include Image):

bin/omero chown 1602 Dataset:4275  --report 
omero.cmd.Chown2 Dataset:4275 ok
Steps: 7
Elapsed time: 18.076 secs.
Flags: []
Included objects
  Dataset:4275
Deleted objects
DatasetImageLink:530366,530368-530374,530376,530378,530379,530381,530383-530385,530387-530392,530394,530395,530397,530399-530404,530406,530407,530409,530410,530412,530414,530415,530417-530423,530425,530427,530429,530431,530432,530434-530440,530442,530444,530446,530447

So now the corresponding images simply vanished from the dataset. Is there any (easy) way to restore these?
Cheers,
Peter

Hi @Peter.Zentis.

If you have a backup of your database, those rows can be re-created. If not, you will need to create new links, but the information about which Dataset linked to which Image is now missing and will have to be recreated.

~Josh

Hi Josh,
In principle I have a backup of the database - I would however not like to modify the database directly because of this. I think I prefer to upload the images anew. What irritates me is that the images do not show up in Orphaned Images now. So do I get it right that the images are still stored on the server and I cut myself from any way to get rid of them (without directly searching the database for images without a DatasetImageLink)?
Thanks, Peter

Are the images perhaps also in another dataset, so not yet orphaned? When logged into that group via OMERO.cli try something like,

bin/omero hql "SELECT parent.name FROM DatasetImageLink WHERE child.id = 12345"

to see which dataset(s) contain image 12345.

With your database backup in hand via psql you can try queries like,

SELECT child FROM DatasetImageLink WHERE parent = 4275;

to find which images were in the dataset. Image 12345 can be placed back into the dataset with,

bin/omero obj new DatasetImageLink parent=Dataset:4275 child=Image:12345

using OMERO.cli without any direct modification of the database. A uniqueness constraint violation probably means that the image is already in the dataset.

Dataset-less images are revealed by,

bin/omero hql "SELECT i.id FROM Image AS i WHERE NOT EXISTS (SELECT 1 FROM DatasetImageLink AS l WHERE l.child.id = i.id) AND NOT EXISTS (SELECT 1 FROM WellSample s WHERE s.image.id = i.id)"