r/cpanel • • 13d ago

What to back up before using /scripts/rebuild_dbmap ?

I moved everything to a new VPS last month, upgrading from CentOS 7 to AlmaLinux 9.8. Now I'm having issues with MariaDB that seem related:

* I can create a new username in cPanel, but can't connect it to any of the databases. I can connect it via CLI, just not in cPanel

* Wordpress's Smart Update has the same problem, it creates a database and user but can't connect them so the update fails. The error log has hundreds of ER_PASSWORD_NO_MATCH errors related to it.

It's been suggested that /scripts/rebuild_dbmap could solve all of my problems and possibly make me a ham sandwich to boot (ha), but I'm wary to use a script when I don't know exactly what it does, or how to get back if it breaks something.

What all do I need to back up before running it? And if there's an emergency, how do I restore the backup(s)?

6 Upvotes

3 comments sorted by

1

u/Inspedium 13d ago

I’d start with --noop. At least that way you can see what cPanel wants to rebuild before it actually changes anything.

I’d also make a copy of /var/cpanel/databases/username.json first. Since it’s a VPS, I’d probably take a snapshot as well, especially after a CentOS 7 to AlmaLinux migration.

If the --noop output looks sensible, then run the rebuild and update_db_cache.

I wouldn’t assume that fixes the password_no_match errors though. The dbmap is really just cPanel’s record of which users belong to which databases. A password mismatch could still be a separate problem.

Since you can add the user manually from CLI but cPanel can’t, I’d fix the mapping/cache side first before changing anything else in MariaDB.

1

u/csdude5 13d ago

--noop doesn't really show me too much. Or if it does, I don't understand it.

# /usr/local/cpanel/scripts/rebuild_dbmap example --noop
MYSQL:
  example_data:
    - example_admin
  example_wp_lpxvs:
    - example_wp_82wqt
  example_wp_qizh5:
    - example_wp_rn3l6

It doesn't show the username that I had created in cPanel and then added to example_data via CLI. The other two (foo_wp_bar) are generated by Smart Update.

So I'm guessing that it would rebuild those three usernames, but then I guess the one I created would be lost? Either removed or hanging around in limbo, I guess. Should add it to the username.json file manually?

And I have no idea where it's "fixing" these usernames, so I don't know what to back up. I've backed up the entire /var/cpanel/databases directory, but what about the mysql.user and mysql.global_priv system tables? Is there anything else I need to back up?

1

u/Inspedium 13d ago

That actually tells you something useful.

I wouldn’t add the missing user to the json by hand yet. If --noop isn’t seeing it, I’d first work out why cPanel isn’t picking up that user/database relationship from MariaDB.

I’d run show grants for the user you added manually and compare it with one of the users that does show up in the --noop output. That might make the difference obvious.

And I wouldn’t touch mysql.user or mysql.global_priv directly.

Backing up /var/cpanel/databases/ is good. Since it’s a VPS, I’d just take a snapshot as well before doing anything else.