Migrations plugin fails: General error: 2006 MySQL server has gone away

I’m trying to migrate a matomo DB to a new server. As instructed I updated both instances to the latest version. I also stopped tracking on the source.

First issue I had was not enough memory in php which I have fixed by adding the following to the beginning of console-file: ini_set(‘memory_limit’, ‘4096M’);

I can access the remote database with mysql command and issue sql statements without errors.

I start the migration with the following command:
./console migration:measurable --source-idsite=“1” --target-db-host=“195.xxx.xxx.xxx” --target-db-username=“matomoUsr” --target-db-password=“xxxxxxxxxxx” --target-db-name="matomoMySite --target-db-prefix=“matomo_”

The output:
Processing SiteMigration at 2022-06-14 07:02:09
Target site is 11 at 2022-06-14 07:02:09
Processed SiteMigration at 2022-06-14 07:02:09
Processing SiteUrlMigration at 2022-06-14 07:02:09
Found 1 site urls at 2022-06-14 07:02:09
Processed SiteUrlMigration at 2022-06-14 07:02:09
Processing SiteSettingMigration at 2022-06-14 07:02:09
Found 3 site settings at 2022-06-14 07:02:09
Processed SiteSettingMigration at 2022-06-14 07:02:10
Processing GoalsMigration at 2022-06-14 07:02:10
Found 0 goals at 2022-06-14 07:02:10
Processed GoalsMigration at 2022-06-14 07:02:10
Processing SegmentsMigration at 2022-06-14 07:02:10
Found 0 segments at 2022-06-14 07:02:10
Processed SegmentsMigration at 2022-06-14 07:02:10
Processing AnnotationsMigration at 2022-06-14 07:02:10
Processed AnnotationsMigration at 2022-06-14 07:02:10
Processing CustomDimensionMigration at 2022-06-14 07:02:10
Found 0 custom dimensions at 2022-06-14 07:02:10
Processed CustomDimensionMigration at 2022-06-14 07:02:10
Processing LogMigration at 2022-06-14 07:02:10
Found 174269 visits at 2022-06-14 07:02:10
Migrated 5% of visits at 2022-06-14 07:35:17
Migrated 10% of visits at 2022-06-14 07:53:18
Migrated 20% of visits at 2022-06-14 08:21:36
Migrated 21% of visits at 2022-06-14 08:21:36
Migrated 22% of visits at 2022-06-14 08:21:36
Migrated 23% of visits at 2022-06-14 08:35:08
Migrated 24% of visits at 2022-06-14 08:35:08
Migrated 25% of visits at 2022-06-14 08:35:08
Migrated 26% of visits at 2022-06-14 08:35:08
Migrated 27% of visits at 2022-06-14 08:35:08
Migrated 28% of visits at 2022-06-14 08:35:08

WARNING [2022-06-14 08:46:42] 11196 /www/html/mysite/matomo/libs/Zend/Db/Statement/Pdo.php(233): Warning - Error while sending QUERY packet. PID=11196 - Matomo 4.10.1 - Please report this message in the Matomo forums: https://forum.matomo.org (please do a search first as it might have been reported already)
ERROR [2022-06-14 08:46:47] 11196 Uncaught exception: /www/html/mysite/matomo/libs/Zend/Db/Statement/Pdo.php(236): SQLSTATE[HY000]: General error: 2006 MySQL server has gone away [Query: , CLI mode: 1]

[Zend_Db_Statement_Exception]
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

[PDOException]
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

I added single percent steps between 20 and 40 percent to get a more detailed picture when exactly the migration fails.

On the remote database I increased the memory for packets as well as for the timeouts:
set global max_allowed_packet=33554432;
set global net_write_timeout=240;
set global net_read_timeout=120;
However that did not change anything. Mysql server on target is running since 200+ days without interruption.

Any hints to fix this issue? I also appreciate instructions how to dump, modify and import it in the new database manually.