Cyberpanel's database restore/repair

Hi everyone,

I was working on some docker installation (while having a sleepy head), and accidentally dropped my “cyberpanel” database tables instead of the “nextcloud” database :man_facepalming:

Now the Cyperpanel cannot be accessed anymore, giving a “Server Error (500)”. I can still access OLS web interface, homebridge and hosted websites, however I do wish Cyberpanel to be restored if possible.

I tried running the Cyberpanel upgrade script and the solution provided below, but that seems unsuccessful.

The above solution results in:

OS: Ubuntu 20.04.6
CP version: cannot see now, did upgrade yesterday so should be latest.

Help is appreciated! TNX

Traceback (most recent call last):
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 219, in ensure_connection
self.connect()
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 200, in connect
self.connection = self.get_new_connection(conn_params)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/backends/mysql/base.py”, line 234, in get_new_connection
return Database.connect(**conn_params)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/MySQLdb/init.py”, line 130, in Connect
return Connection(*args, **kwargs)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/MySQLdb/connections.py”, line 185, in init
super().init(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (1045, “Access denied for user ‘cyberpanel’@‘localhost’ (using password: YES)”)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “upgrade.py”, line 3072, in
main()
File “upgrade.py”, line 3068, in main
Upgrade.upgrade(args.branch)
File “upgrade.py”, line 2980, in upgrade
Upgrade.UpdateConfigOfCustomACL()
File “upgrade.py”, line 2872, in UpdateConfigOfCustomACL
for acl in ACL.objects.all():
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/models/query.py”, line 287, in iter
self._fetch_all()
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/models/query.py”, line 1308, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/models/query.py”, line 53, in iter
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/models/sql/compiler.py”, line 1154, in execute_sql
cursor = self.connection.cursor()
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 259, in cursor
return self._cursor()
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 235, in _cursor
self.ensure_connection()
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 219, in ensure_connection
self.connect()
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/utils.py”, line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 219, in ensure_connection
self.connect()
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/backends/base/base.py”, line 200, in connect
self.connection = self.get_new_connection(conn_params)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/django/db/backends/mysql/base.py”, line 234, in get_new_connection
return Database.connect(**conn_params)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/MySQLdb/init.py”, line 130, in Connect
return Connection(*args, **kwargs)
File “/usr/local/CyberPanel/lib/python3.8/site-packages/MySQLdb/connections.py”, line 185, in init
super().init(*args, **kwargs2)
django.db.utils.OperationalError: (1045, “Access denied for user ‘cyberpanel’@‘localhost’ (using password: YES)”)
above command failed…
root@techxweb:~#

Its impossible reinstall cyberpanel using script… always have a error.

I trie this:

If someone else also deleted their “cyberpanel” database, here are the steps to help you restore it:

1 - Run this command to recreate the database structure:

sh <(curl https://raw.githubusercontent.com/tbaldur/cyberpanel-mods/main/restore_cyberpanel_database.sh || wget -O - https://raw.githubusercontent.com/tbaldur/cyberpanel-mods/main/restore_cyberpanel_database.sh)

dont work!!!

error

“Access denied for user ‘cyberpanel’@‘localhost’” in your error log, means your database password is NOT the one written on the /etc/cyberpanel/mysqlPassword file. You either changed or a cyberpanel upgrade messed it. You have to manually update it if you want to use the script.

Read the sql from the script (https://raw.githubusercontent.com/tbaldur/cyberpanel-mods/main/cyberpanel.sql), if you’re missing the table loginSystem_administrator as written in the error you posted, manually run the query:


CREATE TABLE `loginSystem_administrator` (
  `id` int(11) NOT NULL,
  `userName` varchar(50) NOT NULL,
  `password` varchar(200) NOT NULL,
  `firstName` varchar(20) NOT NULL,
  `lastName` varchar(20) NOT NULL,
  `email` varchar(50) NOT NULL,
  `type` int(11) NOT NULL,
  `owner` int(11) NOT NULL,
  `token` varchar(500) NOT NULL,
  `api` int(11) NOT NULL,
  `securityLevel` int(11) NOT NULL,
  `state` varchar(10) NOT NULL,
  `initWebsitesLimit` int(11) NOT NULL,
  `twoFA` int(11) NOT NULL,
  `secretKey` varchar(50) NOT NULL,
  `config` longtext NOT NULL,
  `acl_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


INSERT INTO `loginSystem_administrator` (`id`, `userName`, `password`, `firstName`, `lastName`, `email`, `type`, `owner`, `token`, `api`, `securityLevel`, `state`, `initWebsitesLimit`, `twoFA`, `secretKey`, `config`, `acl_id`) VALUES
(1, 'admin', 'a533519eb243b30d3623105f4c9590ff3acdb2819b11919c89d1665e1f637e9e:8ca6d87855f946d9995ddb30bc054059', 'Cyber', 'Panel', '[email protected]', 1, 1, 'Basic YWRtaW46NWhwa3hrZmpuS094aWtmQw==', 0, 0, 'ACTIVE', 0, 0, 'None', '{}', 1);

Don’t remember the password at the insert, should be the default 1234567 one from cyberpanel

Hello!, I was trying to use this to re-create the DB in a remote mysql installation (since the cyberpanel user does not work correctly when selecting remote mysql installation). But I got this error:

ERROR 1064 (42000) at line 1251: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE TABLE `IncBackups_backupjob` (
  `id` int(11) NOT NULL,
  `destination...' at line 24