Do you have the REST API enabled? The following endpoint will provide a dump of the hierarchy that is easy to parse.
If that does not help, here are some SQL that might help.
with recursive r_comm2coll as (
select
community_id,
collection_id
from
community2collection
union
select
cm2cm.parent_comm_id as community_id,
r.collection_id
from
r_comm2coll r
inner join
community2community cm2cm
on
cm2cm.child_comm_id = r.community_id
)
select distinct
commh.handle as CommHandle,
collh.handle as CollHandle,
(
select text_value
from metadatavalue mv
where
mv.resource_id=commh.resource_id and mv.resource_type_id=4
and metadata_field_id = (
select metadata_field_id
from metadatafieldregistry where element='title' and qualifier is null
)
) as CommName,
(
select text_value
from metadatavalue mv
where
mv.resource_id=collh.resource_id and mv.resource_type_id=3
and metadata_field_id = (
select metadata_field_id
from metadatafieldregistry where element='title' and qualifier is null
)
) as CollName
from
handle commh
inner join r_comm2coll
on r_comm2coll.community_id=commh.resource_id and commh.resource_type_id=4
inner join handle collh
on r_comm2coll.collection_id=collh.resource_id and collh.resource_type_id=3
order by CommHandle,CollHandle