升级问题

1. 导入数据库报错

  1. ./jmsctl.sh restore_db /opt/jumpserver.sql
  1. 开始还原数据库: /opt/jumpserver.sql
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. ERROR 1022 (23000) at line 1237: Can't write; duplicate key in table 'xxxxxx'
  4. ERRO[0008] error waiting for container: context canceled
  5. read unix @->ar/run/docker.sock: read: connection reset by peer
  6. 数据库恢复失败,请检查数据库文件是否完整,或尝试手动恢复!
  1. ./jmsctl.sh stop
  1. docker exec -it jms_mysql /bin/bash
  1. # 如果变量 $MARIADB_ROOT_PASSWORD 不存在,请使用 $MYSQL_ROOT_PASSWORD
  2. mysql -uroot -p$MARIADB_ROOT_PASSWORD
  1. drop database jumpserver;
  2. create database jumpserver default charset 'utf8';
  3. exit;
  4. exit
  1. ./jmsctl.sh restore_db /opt/jumpserver.sql
  2. # 注意: 确定在导入数据库的过程中没有错误
  1. ./jmsctl.sh start

2. 升级过程提示错误

  1. ./jmsctl.sh upgrade

Table ‘表名’ already existsCannot add foreign key constraint

  1. Operations to perform:
  2. Apply all migrations: acls, admin, applications, assets, audits, auth, authentication, captcha, common, contenttypes, django_cas_ng, django_celery_beat, jms_oidc_rp, notifications, ops, orgs, perms, sessions, settings, terminal, tickets, users
  3. Running migrations:
  4. Applying tickets.0010_auto_20210812_1618...Traceback (most recent call last):
  5. File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute
  6. return self.cursor.execute(sql)
  7. File "/usr/local/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
  8. return self.cursor.execute(query, args)
  9. File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
  10. res = self._query(query)
  11. File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
  12. db.query(q)
  13. File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
  14. _mysql.connection.query(self, query)
  15. MySQLdb._exceptions.OperationalError: (1050, "Table 'tickets_approvalrule' already exists")

此错误通常于手动导入备份数据库后启动出现,原因一般为新的数据库名称与旧数据库名称不一致或者导入数据库过程有错误导致。如果升级过程中异常终止,第二次执行升级也可能会出现此错误,可以尝试还原数据库后重新升级。

  1. Operations to perform:
  2. Apply all migrations: acls, admin, applications, assets, audits, auth, authentication, captcha, common, contenttypes, django_cas_ng, django_celery_beat, jms_oidc_rp, notifications, ops, orgs, perms, sessions, settings, terminal, tickets, users
  3. Running migrations:
  4. Applying assets.0084_auto_20220112_1959...2022-01-24 14:38:47 Perform migrate failed, exit
  5. Traceback (most recent call last):
  6. File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
  7. return self.cursor.execute(sql, params)
  8. File "/usr/local/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
  9. return self.cursor.execute(query, args)
  10. File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
  11. res = self._query(query)
  12. File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
  13. db.query(q)
  14. File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
  15. _mysql.connection.query(self, query)
  16. MySQLdb._exceptions.IntegrityError: (1215, 'Cannot add foreign key constraint')

如果数据库里面包含多种不一样的排序规则依旧会报错。

  1. # 通过 grep 检查 sql 文件
  2. mysqldump -uroot -p jumpserver > jumpserver.sql
  3. # 检查字符集, 如果都返回 utf8 则无问题
  4. grep -r "DEFAULT CHARSET=" jumpserver.sql
  5. # 检查排序规则,正常情况下返回都是空或者唯一
  6. grep -r "COLLATE=" jumpserver.sql
  7. grep -r "COLLATE " jumpserver.sql
  8. # 如果上述结果不一致,请手动修正数据库。