Restored Site - URLS need to be corrected, any ideas?

Did a restore and all the internal links have the test URL domain, breaking all the links and I am not sure why it did not take up the correct site URL, without going into the code/db to do a mass find & replace any solutions on how to do this another way?

I was thinking do a Re-Restore?

You’ll need to go into the db and do a mass search/replace.

There is a tool for that:

RAILS_ENV=production discourse remap //old.domain //new.domain

3 Likes

You can fix it as described, but that shouldn’t happen.

Did you make and restore the backup using /admin/backups?

Do both systems have the hostname set correctly?

2 Likes

Thanks. That looked easy enough. I entered the app and I ran that but it seems not to have changed the instances of the URLs in the posts.

This was the remap:

RAILS_ENV=production discourse remap //https://sub.domain.com //https://domain.com

This ran and competed on the “default” DB it took a few mins and then reported “done” with no error.

I looked at a few choice posts and nothing seemed to have changed on any posts URLs link.

I rebuilt some to test where I saw the dev.domain.com instead of the live domain.com in the links, but they remain the same.

Then I ran the same but sans the https:// and got this error

Remapping tables on default...

Error: ERROR:  duplicate key value violates unique constraint "index_post_hotlinked_media_on_post_id_and_url_md5"
DETAIL:  Key (post_id, md5(url::text))=(1001176, 547048fcd29cdac60) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.

I’m guessing there is a chat message in the DB that’s causing it to stop but not sure why. I suppose I need to somehow see that in the DB, as you can tell no my usual foray in managing discourse is never in the DB.

Finally, I re-ran the original remap, it took a few mins and reported as “done” with no errors:

RAILS_ENV=production discourse remap //https://sub.domain.com //https://domain.com

:thinking:

Maybe I need to rebake posts to see the fruits?

I thought a post rebuild was the same action on but on a post by post basis.

Or rebuild the app?

That should be

RAILS_ENV=production discourse remap //sub.domain.com //domain.com

The reason for // is that it matches http://, https:// and protocol-less URLs, and it does not match e-mail address domains.

What happens when you do that?

2 Likes

Yea ok, then same error again:

Remapping tables on default...

Error: ERROR:  duplicate key value violates unique constraint "index_post_hotlinked_media_on_post_id_and_url_md5"
DETAIL:  Key (post_id, md5(url::text))=(1001176, 547048fcd29cdac60) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.

So at least I’m using the right write command, things are looking up! :slight_smile:

No further ideas?

Apart from this rails remap impasse I thought maybe if I backup the db and do a restore again it might remap the Link-urls correctly during the restore process?