How can I regenerate memberships shared by relationship?
I ran into a situation where the membership-type relationships were missing a relationship type, so I had to re-generate the related memberships.

Instead of export/import, I used the CiviCRM API:

$result = civicrm_api3('Membership', 'get', [
  'membership_type_id' =&gt; 1234, // optional
  'option.limit' =&gt; 0,
]);

foreach ($result['values'] as $key =&gt; $val) {
  civicrm_api3('Membership', 'create', [
    'id' =&gt; $val['id'],
  ]);
}


The Membership BAO calls createRelatedMemberships.

update: however, I had a small issue with the Membership dashboard not reflecting the numbers correctly, and had to run this query:

UPDATE civicrm_membership m
  LEFT OUTER JOIN civicrm_membership parent ON (parent.id = m.owner_membership_id)
SET m.join_date = parent.join_date, m.end_date = parent.end_date, m.start_date = parent.start_date
WHERE m.membership_type_id = 1234
  AND m.start_date is null;