Change sharing link path after server IP/hostname change

Nextcloud version: Nextcloud Hub II (23.0.1 RC3)
Operating system and version: Ubuntu 20.04
Apache or nginx version: Apache 2.4.25
PHP version: 7.4

The issue you are facing:

We have more than 200 sharing links. We had to migrate nextcloud on a different server with different lan IP and hostname and we lost access to the folders through those links.

Any chance to bulk modify the path in links database or fix that issue without renaming links one by one ?

Sort answer, nope !!!

Host name change … old lshare links are directed to the wrong hostname. Game over. Even with some tricky rewrite direction rules

The same links still work on the new hostname? In this case, the rewrite rules could be a solution (if you have access to the old hostname).

Links are not working anymore.
I thought there would be a database where I could change the path before the token id

I have word file containing all the olds links, any chance to inject them with a sql command ?

also, in case this is impossible, how can I cleanup the old links database as I cannot recreate the links manually because it says token already exist

You have a share table. But there is no hostname. If you create a new share, is it working with the new hostname? And then you can check the difference with the old shares in the table.

There’s no way around using the new “hostname”, respective the new (sub.) if you changed it in your web server and Nextcloud config. The “…/s/m4PGe879bx578y” part of the links should stay the same but your users have to use the new hostname in front of it, like that: https://newhostname/s/m4PGe879bx578yE

But why did you change the domain name in the URL in the first place? Normaly you would just point the DNS records for cloud.domain.tld or cloud.tld to the new IP (A record) or to the hostname of the new server (CNAME) when you migrate web applications like Nextcloud to a new server…

actually it’s the IP the issue.
The new server is on a different subnet and external storages where using the lan ip as hostname.

If you’re using the IP address of the server in order to access your Nextcloud there is no way to preserve the links when you migrate Nextcloud to a server with another IP address. The only way would be using a DNS name and then point that name to the IP address of the new server. Obviously such a DNS setup would have to be already in place before the migration.

Grumpy me : As I said :

Host name change … old lshare links are directed to the wrong hostname. Game over. Even with some tricky rewrite direction rules…

It was anyway an interesting question, so I did try some rewrite rules on my test bench… Always end up crashing… Even for old links using sharerenamer app …

Think we can now close this subject…

solved it by adding additional network interface with the old ip address on the new server.
old links are working again

Thanks for your help guys

Maybe a bit offtopic, but I would always use hostnames for your Nextcloud. It is easier to remember, if you move to a different ip, there is no problem, and you can get ssl certificates.