Question
How do I dump a cPanel database using an API token?
Answer
cPanel's MysqlDump stream sends a database dump over a WebSocket. You authenticate with an API token, so you do not need SSH access.
Note: The MysqlDump stream is experimental, and its behavior may change in a future version of cPanel & WHM.
- Log in to cPanel.
- Navigate to Home / Security Manage API Tokens.
- Click Create, enter a name, and set an expiration.
- Copy the token. cPanel displays it only once.
-
Next, on the client, you need to install the WebSocket Client.
# npm install -g wscat
-
On the client machine where we installed wscat, run the dump.
Note: Please replace
USERNAMEwith your cPanel username.API_TOKENwith the token from Step 1.SERVER_HOSTNAMEwith any hostname that resolves to the server and finally,USERNAME_DBNAMEwith the full database name, including the prefix. Additionally, the following is required: Replace thecharacter_setwith the character set you need.utf8mb4orutf8If you receive a collation error, and theinclude_data.Where1includes table data;0dumps structure only.# wscat -H "Authorization: cpanel USERNAME:API_TOKEN" -c "wss://SERVER_HOSTNAME:2083/websocket/MysqlDump?dbname=USERNAME_DBNAME&include_data=1&character_set=utf8mb4" > $
USERNAME_DBNAME.sql
Additional Resources
- Close code 1000: The dump succeeded.
-
Close code 4000: Collation error. Retry with
character_set=utf8. -
Close code 1011: General error. The close frame includes an error ID. An administrator can search
/usr/local/cpanel/logs/error_logfor it. -
Certificate errors: Use a hostname with a valid certificate, or add
--no-checktowscatfor a self-signed certificate. - The MysqlDump Stream
Comments
0 comments
Please sign in to leave a comment.