Database abnormal state repair method and system based on maintenance mode
By building a maintenance mode, generating and verifying passwords, loading template files and data playback tools, the problem of data recovery under abnormal database conditions is solved, and efficient data repair and recovery is achieved.
Patent Information
- Application Number
- CN202411449252.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2044-10-17
AI Technical Summary
In the Linux operating system's safe mode, when a major database failure occurs, such as forgetting the administrator account or physical file damage, it is difficult to access the database and recover data.
By building a maintenance mode, generating and verifying the maintenance mode password, loading template files, using the data playback tool to restore data in maintenance mode, and performing operation audits.
Without initializing the database, it repairs abnormal database status, ensures data recovery, prevents interference from other users, and provides an efficient data recovery mechanism.
Smart Images

Figure CN119493681B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases, and in particular to a method and system for repairing abnormal database states based on a maintenance mode. Background Art
[0002] In the Linux operating system's safe mode, the system runs in a minimized state, loading only the most essential services and drivers, and disabling network services and other non-essential services. Its main purpose is to provide system administrators with a safe environment to repair system problems, such as repairing damaged system files, recovering forgotten root passwords, and resolving startup issues.
[0003] Referring to the security mode of Linux itself, when a major failure occurs in the database, such as forgetting the administrator account, being unable to log in to the system, physical file damage, and the database being unable to start, it is difficult to repair. When the database enters an abnormal state and cannot be logged in, how to enter the database and recover the data is a technical problem that needs to be solved. Summary of the Invention
[0004] The technical task of the present invention is to address the above shortcomings and provide a database abnormal state repair method and system based on maintenance mode to solve the technical problem of how to enter the database and restore data when the database enters an abnormal state and cannot be logged in.
[0005] In a first aspect, the present invention provides a method for repairing an abnormal state of a database based on a maintenance mode, comprising the following steps:
[0006] Maintenance mode construction: Build the maintenance mode of the database. The maintenance mode runs on the server where the database is located and is started by the database master process.
[0007] Maintenance mode password generation: The password entered when the database directory is initialized is used as the maintenance mode password. When the database is initialized, the maintenance mode password is entered through the interactive interface returned by the database. The hash value of the maintenance mode password is calculated as the check value and stored in the database directory;
[0008] Maintenance mode password verification: When maintenance mode is started, the password used when initializing the database directory is entered through the interactive interface returned by the database. The hash value of the entered password is calculated and compared with the generated hash value. If they are the same, the verification is passed and the database can enter maintenance mode.
[0009] Maintenance mode startup: When the database enters maintenance mode, it loads two specified template files. If at least one of the template files is loaded successfully, the database enters maintenance mode. The two specified template files are the initial form files formed after the database is initialized.
[0010] Data playback: In maintenance mode, the data added by the user can be played back through the data playback tool;
[0011] Operation audit: Log the operation process of maintenance mode password generation, maintenance mode password verification, maintenance mode startup and data playback, store the recorded operation log in the audit log, and view it through the audit log after the database recovers from the abnormal state.
[0012] Preferably, the maintenance mode password generation includes the following steps:
[0013] When the database is initialized, an interactive interface for the maintenance mode password is returned through the database. The password entered when the database directory is initialized is entered through the interactive interface as the maintenance mode password;
[0014] The maintenance mode password entered is checked for complexity. The complexity check rule is: the minimum length is 8 characters and must include uppercase and lowercase letters, numbers, and characters.
[0015] Perform a hash calculation on the maintenance mode password that passes the complexity check. Use the user's local network card physical address (MAC address) as the key and hash the maintenance mode password using the HMAC SM3 hash algorithm. Store the resulting hash value as the check value in the MM.key file, which is then placed in the database's data directory, data.
[0016] Correspondingly, maintenance mode password verification includes the following steps:
[0017] When starting the maintenance mode, the database returns an interactive interface for the maintenance mode password, and the password entered when the database directory was initialized is entered through the interactive interface;
[0018] Using the user's local network card physical address MAC address as the key, the input password is hashed through the HMAC SM3 hash algorithm, and the generated hash value is compared with the check value in the MM.key file under the data directory data. If they are the same, the verification is passed and the database can enter maintenance mode, otherwise it exits.
[0019] Preferably, during the maintenance mode startup process, after the database enters the maintenance mode, the network connection is closed in the maintenance mode.
[0020] Preferably, the data playback tool is a Database Playback tool.
[0021] Preferably, data playback includes system data playback and user data playback;
[0022] When replaying system data, a temporary system table is created, the system table to be replayed is stored in the temporary system table, and a connection test is performed on the system table. If there is abnormal data in the original system table, the abnormal system table with abnormal data is read row by row, and the normal data in the abnormal system table is stored in the temporary system table. When abnormal data is read, the abnormal data is skipped and the location of the abnormal data is recorded in the abnormal log. The next row is read until the abnormal system table is read. The data in the temporary system table is copied to the normal table, and the data recorded in the abnormal log is discarded.
[0023] The data file corresponding to the user data is a newly created physical file. When replaying the user data, the data is replayed by copying the user data physical file.
[0024] In a second aspect, the present invention provides a maintenance mode-based database abnormal state repair system, which is used to repair a database abnormal state using a maintenance mode-based database abnormal state repair method as described in any one of the first aspects, wherein the system includes a maintenance mode construction module, a maintenance mode password generation module, a maintenance mode password verification module, a maintenance mode startup module, a data playback module, and an operation audit module;
[0025] The maintenance mode building module is used to perform the following: build the maintenance mode of the database, which runs on the server where the database is located and is started by the database master process;
[0026] The maintenance mode password generation module is used to perform the following: using the password entered when the database directory is initialized as the maintenance mode password, entering the maintenance mode password through the interactive interface returned by the database when the database is initialized, calculating the hash value of the maintenance mode password as a check value and storing it in the database directory;
[0027] The maintenance mode password verification module is used to perform the following operations: when the maintenance mode is started, the password used when initializing the database directory is entered through the interactive interface returned by the database, the hash value of the entered password is calculated, and the generated hash value is compared with the checksum value. If they are the same, the verification is passed and the database can enter the maintenance mode;
[0028] The maintenance mode startup module is used to perform the following: loading two specified template files when the database enters the maintenance mode, and if at least one of the template files is loaded successfully, the database enters the maintenance mode, wherein the two specified template files are initial form files formed after the database is initialized;
[0029] The data playback module is used to perform the following operations: in maintenance mode, replay the data added by the user through the data playback tool;
[0030] The operation audit module is used to perform the following: log the operation process of maintenance mode password generation, maintenance mode password verification, maintenance mode startup and data playback, store the recorded operation log in the audit log, and view it through the audit log after the database recovers from the abnormal state.
[0031] Preferably, the maintenance mode password generation module is configured to perform the following operations:
[0032] When the database is initialized, an interactive interface for the maintenance mode password is returned through the database. The password entered when the database directory is initialized is entered through the interactive interface as the maintenance mode password;
[0033] The maintenance mode password entered is checked for complexity. The complexity check rule is: the minimum length is 8 characters and must include uppercase and lowercase letters, numbers, and characters.
[0034] Perform a hash calculation on the maintenance mode password that passes the complexity check. Use the user's local network card physical address (MAC address) as the key and hash the maintenance mode password using the HMAC SM3 hash algorithm. Store the resulting hash value as the check value in the MM.key file, which is then placed in the database's data directory, data.
[0035] Correspondingly, the maintenance mode password verification module is used to perform the following operations:
[0036] When starting the maintenance mode, the database returns an interactive interface for the maintenance mode password, and the password entered when the database directory was initialized is entered through the interactive interface;
[0037] Using the user's local network card physical address MAC address as the key, the input password is hashed through the HMAC SM3 hash algorithm, and the generated hash value is compared with the check value in the MM.key file under the data directory data. If they are the same, the verification is passed and the database can enter maintenance mode, otherwise it exits.
[0038] Preferably, during the maintenance mode startup process, after the database enters the maintenance mode, the maintenance mode startup module is used to close the network connection in the maintenance mode.
[0039] Preferably, the data playback tool is a Database Playback tool.
[0040] Preferably, data playback includes system data playback and user data playback;
[0041] When replaying system data, the data replay module is used to perform the following operations: create a temporary system table, store the system table to be replayed in the temporary system table, and perform a connection test on the system table. If there is abnormal data in the original system table, read the abnormal system table line by line for the abnormal system table with abnormal data, and store the normal data in the abnormal system table in the temporary system table. When abnormal data is read, skip the abnormal data, record the location of the abnormal data in the abnormal log, and read the next line until the abnormal system table is finished reading. Then copy the data in the temporary system table to the normal table, and discard the data recorded in the abnormal log.
[0042] The data file corresponding to the user data is a newly added physical file. When replaying the user data, the data replay module is used to replay the data by copying the user data physical file.
[0043] The maintenance mode-based database abnormal state repair method and system of the present invention have the following advantages:
[0044] 1. The database can repair abnormal status in maintenance mode and complete the repair of abnormal status without initializing the database;
[0045] 2. The database can skip the damaged blocks of the physical files and complete the transfer of normal data, enabling the database to run in maintenance mode and repair its abnormal status. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0047] The present invention will be further described below with reference to the accompanying drawings.
[0048] Figure 1 This is a flowchart of a method for repairing abnormal database status based on maintenance mode in Example 1;
[0049] Figure 2 This is a flowchart of maintenance mode password generation and maintenance mode password verification in a maintenance mode-based database abnormal state repair method in Example 1. DETAILED DESCRIPTION
[0050] The present invention will be further described below with reference to the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments given are not intended to limit the present invention. Unless there is a conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.
[0051] The embodiments of the present invention provide a maintenance mode-based database abnormal state repair method and system for solving the technical problem of how to access the database and restore data when the database enters an abnormal state and cannot be logged in.
[0052] Example 1:
[0053] The invention provides a maintenance mode-based database abnormal state repair method, which includes six steps: maintenance mode construction, maintenance mode password generation, maintenance mode password verification, maintenance mode startup, data playback and operation audit.
[0054] Step S100: Maintenance mode construction: constructing a maintenance mode of the database. The maintenance mode runs on the server where the database is located and is started by the database main process.
[0055] When the database is in an abnormal state, normal database connections cannot be made and the database cannot be accessed through normal database connections. This embodiment designs a maintenance mode. Maintenance mode can only be run on the database server and is initiated by the database master process. To start maintenance mode, the following command is used: database start Maintenance Mode -D database data directory.
[0056] Step S200: Generate maintenance mode password: Use the password entered when initializing the database directory as the maintenance mode password. When the database is initialized, enter the maintenance mode password through the interactive interface returned by the database. Calculate the hash value of the maintenance mode password as the verification value and store it in the database directory.
[0057] As a specific implementation, the maintenance mode password generation includes the following steps:
[0058] (1) When the database is initialized, an interactive interface for the maintenance mode password is returned through the database, and the password entered when the database directory is initialized is entered through the interactive interface as the maintenance mode password;
[0059] (2) Perform a complexity check on the maintenance mode password entered. The complexity check rule is: the minimum length is 8 characters and must include uppercase and lowercase letters, numbers, and characters;
[0060] (3) Perform hash calculation on the maintenance mode password that has passed the complexity check, use the user's local network card physical address MAC address as the key, hash the maintenance mode password using the HMAC SM3 hash algorithm, store the obtained hash value as the check value in the MM.key file, and place the MM.key file in the data directory data of the database.
[0061] While in maintenance mode, arbitrary operations are possible, resulting in excessive permissions. Therefore, a key is required to manage the current login at startup. This key is independent of the database user and is associated with the password entered when initializing the database directory. The password is hashed using a hash function and stored in the database's data directory as the key for initiating maintenance mode. This file is set to MM.key. During normal database use, this password is not verified, which does not affect normal database operation. However, after maintenance mode is enabled, the password is verified and validated.
[0062] Step S300 Maintenance mode password verification: When the maintenance mode is started, the password used when initializing the database directory is entered through the interactive interface returned by the database, the hash value of the input password is calculated, and the generated hash value is compared with the check value. If they are the same, the verification is passed and the database can enter the maintenance mode.
[0063] As a specific implementation, maintenance mode password verification includes the following steps:
[0064] (1) When the maintenance mode is started, an interactive interface for the maintenance mode password is returned through the database, and the password entered when the database directory was initialized is entered through the interactive interface;
[0065] (2) Using the user's local network card physical address MAC address as the key, the input password is hashed through the HMAC SM3 hash algorithm, and the generated hash value is compared with the check value in the MM.key file under the data directory data. If they are the same, the verification is passed and the database can enter the maintenance mode, otherwise it exits.
[0066] Step S400 maintenance mode starts: when the database enters maintenance mode, two specified template files are loaded. If at least one of the template files is loaded successfully, the database enters maintenance mode. The two specified template files are the initial form files formed after the database is initialized.
[0067] When a database enters maintenance mode, it's uncertain whether the current database's user data files are damaged, so it starts in an initialized form. During startup, it searches for template files, which are the database's initial form. After the database is initialized, two template files are created: template0 and template1. When entering maintenance mode, the database attempts to load these two template files in sequence. If one of them loads successfully, maintenance mode is entered, and the database is in a completely new state. The advantage of this is that when the database is in an abnormal state, there's no need to reinitialize the database directory; a completely new database is generated. This new database disregards any user-written data, and user-written data will not affect the database's functionality.
[0068] After the database enters maintenance mode, in order to prevent other users' connection data from affecting the current recovery operation, the network connection will be closed in maintenance mode and other users' connections will be prohibited. In this way, the maintainer can perform corresponding operations in maintenance mode without being affected by other users.
[0069] Step S500: Data playback: In the maintenance mode, the data added by the user is played back through the data playback tool.
[0070] The database playback tool, Database Playback Tool (DP Tool), is used in this embodiment to replay data in several abnormal database situations. During database maintenance, the database is in a completely new state, devoid of user data. Ultimately, the database needs to be restored to a previously usable state, so replaying user-added data is necessary.
[0071] Data playback includes system data playback and user data playback.
[0072] When replaying system data, use the following command to replay the system data file: DP –sysdata.
[0073] When entering maintenance mode, the database itself processes the initialization state. At this time, the system data is already in the database. At this time, replay will affect the system data of its own database. At this time, when the system data is replayed, a temporary system table is created, and the system table to be replayed is stored in the temporary system table, and a connection test is performed on the system table. If there is abnormal data in the original system table, for the abnormal system table with abnormal data, the abnormal system table is read line by line, and the normal data in the abnormal system table is stored in the temporary system table. When abnormal data is read, the abnormal data is skipped, and the position of the abnormal data is recorded in the abnormal log, and the next line is read until the abnormal system table is read. The data in the temporary system table is copied to the normal table, and the data recorded in the abnormal log is discarded.
[0074] For example, when replaying data, the sys_user table stores user information and is used when connecting to the database. When replaying data, a new sys_user_temp table is created in the database system, and a connection test is performed on each user row in the table to ensure that the data is normal. The following two situations may occur:
[0075] Case 1: If the maintenance mode is used because a super user has forgotten the password, you can perform a reset operation to reset the super user's password. The command is as follows: DP-sysdata-sys_user-superuser-reset. At this time, the super user's password is reset and the initial password can be used to connect.
[0076] Case 2: The data file of the system data itself is damaged. When reading the original data, when the damaged block is read, the database will report an error, causing database abnormality. At this time, it is necessary to read the abnormal table line by line, and put the normal data into a temporary table. When the reading is abnormal, skip the abnormal block, record the abnormal position in the abnormal log, and read the next line until the reading of this data file is completed. At this time, the temporary table is full of normal data. The data in the temporary table is copied to the official table, and the data recorded in the abnormal log is discarded.
[0077] The data file corresponding to the user data is a newly created physical file. When replaying the user data, the data is replayed by copying the user data physical file.
[0078] As a specific implementation of user data playback, use the following command to play back the user data file: DP –userdata.
[0079] User data in the database is stored in separate files from the system data stored in the database itself. These files are newly created physical files, separate from the system data files. Furthermore, these files are typically large. Therefore, when replaying user data, we directly copy the physical files to speed up playback.
[0080] Step S600: Operation audit: Log the operation process of maintenance mode password generation, maintenance mode password verification, maintenance mode startup and data playback, store the recorded operation log in the audit log, and view it through the audit log after the database recovers from the abnormal state.
[0081] Since maintenance mode is an extremely high-authority mode, the entire operation needs to be audited during the maintenance process, and the entire operation process must be logged and stored in the audit log. When the database recovers from the abnormal state, the auditor can use the audit log to check whether there are any unauthorized or illegal operations during the maintenance process.
[0082] The method of this embodiment adds a maintenance mode to the database. When the database is in an abnormal state, the database is started in a minimum state and entered into an initialization state. The maintenance personnel can perform corresponding operations on the database according to the current abnormal state to restore it to a normal state.
[0083] Example 2:
[0084] The invention provides a maintenance mode-based database abnormal state repair system, which includes a maintenance mode construction module, a maintenance mode password generation module, a maintenance mode password verification module, a maintenance mode startup module, a data playback module and an operation audit module.
[0085] The maintenance mode building module is used to perform the following: building a maintenance mode of the database, the maintenance mode runs on the server where the database is located, and is started by the database main process.
[0086] When the database is in an abnormal state, normal database connections cannot be made and the database cannot be accessed through normal database connections. This embodiment designs a maintenance mode. Maintenance mode can only be run on the database server and is initiated by the database master process. To start maintenance mode, the following command is used: database start Maintenance Mode -D database data directory.
[0087] The maintenance mode password generation module is used to perform the following: use the password entered when the database directory is initialized as the maintenance mode password; when the database is initialized, enter the maintenance mode password through the interactive interface returned by the database; calculate the hash value of the maintenance mode password as the verification value and store it in the database directory.
[0088] As a specific implementation, the maintenance mode password generation module is used to perform the following operations:
[0089] (1) When the database is initialized, an interactive interface for the maintenance mode password is returned through the database, and the password entered when the database directory is initialized is entered through the interactive interface as the maintenance mode password;
[0090] (2) Perform a complexity check on the maintenance mode password entered. The complexity check rule is: the minimum length is 8 characters and must include uppercase and lowercase letters, numbers, and characters;
[0091] (3) Perform hash calculation on the maintenance mode password that has passed the complexity check, use the user's local network card physical address MAC address as the key, hash the maintenance mode password using the HMAC SM3 hash algorithm, store the obtained hash value as the check value in the MM.key file, and place the MM.key file in the data directory data of the database.
[0092] While in maintenance mode, arbitrary operations are possible, resulting in excessive permissions. Therefore, a key is required to manage the current login at startup. This key is independent of the database user and is associated with the password entered when initializing the database directory. The password is hashed using a hash function and stored in the database's data directory as the key for initiating maintenance mode. This file is set to MM.key. During normal database use, this password is not verified, which does not affect normal database operation. However, after maintenance mode is enabled, the password is verified and validated.
[0093] The maintenance mode password verification module is used to perform the following: when the maintenance mode is started, the password used when initializing the database directory is entered through the interactive interface returned by the database, the hash value of the input password is calculated, and the generated hash value is compared with the check value. If they are the same, the verification is passed and the database can enter the maintenance mode.
[0094] As a specific implementation, the maintenance mode password verification module is used to perform the following operations:
[0095] (1) When the maintenance mode is started, an interactive interface for the maintenance mode password is returned through the database, and the password entered when the database directory was initialized is entered through the interactive interface;
[0096] (2) Using the user's local network card physical address MAC address as the key, the input password is hashed through the HMAC SM3 hash algorithm, and the generated hash value is compared with the check value in the MM.key file under the data directory data. If they are the same, the verification is passed and the database can enter the maintenance mode, otherwise it exits.
[0097] The maintenance mode startup module is used to execute the following: when the database enters the maintenance mode, it loads two specified template files. If at least one of the template files is loaded successfully, the database enters the maintenance mode, wherein the two specified template files are the initial form files formed after the database is initialized.
[0098] When a database enters maintenance mode, it's uncertain whether the current database's user data files are damaged, so it starts in an initialized form. During startup, it searches for template files, which are the database's initial form. After the database is initialized, two template files are created: template0 and template1. When entering maintenance mode, the database attempts to load these two template files in sequence. If one of them loads successfully, maintenance mode is entered, and the database is in a completely new state. The advantage of this is that when the database is in an abnormal state, there's no need to reinitialize the database directory; a completely new database is generated. This new database disregards any user-written data, and user-written data will not affect the database's functionality.
[0099] After the database enters maintenance mode, in order to prevent other users' connection data from affecting the current recovery operation, the network connection will be closed in maintenance mode and other users' connections will be prohibited. In this way, the maintainer can perform corresponding operations in maintenance mode without being affected by other users.
[0100] The data playback module is used to perform the following: in maintenance mode, the data added by the user is played back through the data playback tool.
[0101] The database playback tool, Database Playback Tool (DP Tool), is used in this embodiment to replay data in several abnormal database situations. During database maintenance, the database is in a completely new state, devoid of user data. Ultimately, the database needs to be restored to a previously usable state, so replaying user-added data is necessary.
[0102] Data playback includes system data playback and user data playback.
[0103] When replaying system data, the data replay module is used to replay the system data file through the following command: DP –sysdata.
[0104] When entering maintenance mode, the database itself processes the initialization state. At this time, the system data is already in the database. At this time, replay will affect the system data of the database itself. When the system data is replayed, the data replay module is used to perform the following operations: create a temporary system table, store the system table that needs to be replayed in the temporary system table, and perform a connection test on the system table. If there is abnormal data in the original system table, for the abnormal system table with abnormal data, read the abnormal system table line by line, and store the normal data in the abnormal system table in the temporary system table. When reading abnormal data, skip the abnormal data, record the position of the abnormal data in the abnormal log, and read the next line until the reading of the abnormal system table is completed, copy the data in the temporary system table to the normal table, and discard the data recorded in the abnormal log.
[0105] For example, when replaying data, the sys_user table stores user information and is used when connecting to the database. When replaying data, a new sys_user_temp table is created in the database system, and a connection test is performed on each user row in the table to ensure that the data is normal. The following two situations may occur:
[0106] Case 1: If the maintenance mode is used because a super user has forgotten the password, you can perform a reset operation to reset the super user's password. The command is as follows: DP-sysdata-sys_user-superuser-reset. At this time, the super user's password is reset and the initial password can be used to connect.
[0107] Case 2: The data file of the system data itself is damaged. When reading the original data, when the damaged block is read, the database will report an error, causing database abnormality. At this time, it is necessary to read the abnormal table line by line, and put the normal data into a temporary table. When the reading is abnormal, skip the abnormal block, record the abnormal position in the abnormal log, and read the next line until the reading of this data file is completed. At this time, the temporary table is full of normal data. The data in the temporary table is copied to the official table, and the data recorded in the abnormal log is discarded.
[0108] The data file corresponding to the user data is a newly created physical file. When replaying the user data, the data is replayed by copying the user data physical file.
[0109] As a specific implementation of user data playback, the data playback module is used to play back the user data file using the following command: DP –userdata.
[0110] User data in the database is stored in separate files from the system data stored in the database itself. These files are newly created physical files, separate from the system data files. Furthermore, these files are typically large. Therefore, when replaying user data, the data replay module directly copies the user data physical files to speed up playback.
[0111] The operation audit module is used to perform the following: log the operation process of maintenance mode password generation, maintenance mode password verification, maintenance mode startup and data playback, store the recorded operation log in the audit log, and view it through the audit log after the database recovers from the abnormal state.
[0112] Since maintenance mode is an extremely high-authority mode, the entire operation needs to be audited during the maintenance process, and the entire operation process must be logged and stored in the audit log. When the database recovers from the abnormal state, the auditor can use the audit log to check whether there are any unauthorized or illegal operations during the maintenance process.
[0113] The system of this embodiment can execute the method disclosed in Example 1 to repair the abnormal state of the database.
[0114] The present invention has been shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the means in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the scope of protection of the present invention.
Claims
1. A method for repairing abnormal state of a database based on maintenance mode, characterized in that: The steps include: Maintenance mode construction: Build the maintenance mode of the database. The maintenance mode runs on the server where the database is located and is started by the database master process. Maintenance mode password generation: The password entered when the database directory is initialized is used as the maintenance mode password. When the database is initialized, the maintenance mode password is entered through the interactive interface returned by the database. The hash value of the maintenance mode password is calculated as the check value and stored in the database directory; Maintenance mode password verification: When maintenance mode is started, the password used when initializing the database directory is entered through the interactive interface returned by the database. The hash value of the entered password is calculated and compared with the generated hash value. If they are the same, the verification is passed and the database can enter maintenance mode. Maintenance mode startup: When the database enters maintenance mode, it loads two specified template files. If at least one of the template files is loaded successfully, the database enters maintenance mode. The two specified template files are the initial form files formed after the database is initialized. Data playback: In maintenance mode, the data added by the user can be played back through the data playback tool; Operation audit: Log the operation process of maintenance mode password generation, maintenance mode password verification, maintenance mode startup and data playback, store the recorded operation log in the audit log, and review it through the audit log after the database recovers from the abnormal state; Among them, data playback includes system data playback and user data playback; When replaying system data, a temporary system table is created, the system table to be replayed is stored in the temporary system table, and a connection test is performed on the system table. If there is abnormal data in the original system table, the abnormal system table with abnormal data is read row by row, and the normal data in the abnormal system table is stored in the temporary system table. When abnormal data is read, the abnormal data is skipped and the location of the abnormal data is recorded in the abnormal log. The next row is read until the abnormal system table is read. The data in the temporary system table is copied to the normal table, and the data recorded in the abnormal log is discarded. The data file corresponding to the user data is a newly created physical file. When replaying the user data, the data is replayed by copying the user data physical file.
2. The method for repairing abnormal database status based on maintenance mode according to claim 1, characterized in that: Generating a maintenance mode password involves the following steps: When the database is initialized, an interactive interface for the maintenance mode password is returned through the database. The password entered when the database directory is initialized is entered through the interactive interface as the maintenance mode password; The maintenance mode password entered is checked for complexity. The complexity check rule is: the minimum length is 8 characters and must include uppercase and lowercase letters, numbers, and characters. Perform a hash calculation on the maintenance mode password that passes the complexity check. Use the user's local network card physical address (MAC address) as the key and hash the maintenance mode password using the HMAC SM3 hash algorithm. Store the resulting hash value as the check value in the MM.key file, which is then placed in the database's data directory, data. Correspondingly, maintenance mode password verification includes the following steps: When starting the maintenance mode, the database returns an interactive interface for the maintenance mode password, and the password entered when the database directory was initialized is entered through the interactive interface; Using the user's local network card physical address MAC address as the key, the input password is hashed through the HMAC SM3 hash algorithm, and the generated hash value is compared with the check value in the MM.key file under the data directory data. If they are the same, the verification is passed and the database can enter maintenance mode, otherwise it exits.
3. The method for repairing abnormal database status based on maintenance mode according to claim 1, characterized in that: During maintenance mode startup, after the database enters maintenance mode, network connections are closed in maintenance mode.
4. The method for repairing abnormal database status based on maintenance mode according to claim 1, characterized in that: The data playback tool is the Database Playback tool.
5. A database abnormal state repair system based on maintenance mode, characterized in that: A system for repairing a database abnormal state by using a maintenance mode-based database abnormal state repair method according to any one of claims 1 to 4, the system comprising a maintenance mode construction module, a maintenance mode password generation module, a maintenance mode password verification module, a maintenance mode startup module, a data playback module, and an operation audit module; The maintenance mode building module is used to perform the following: build the maintenance mode of the database, which runs on the server where the database is located and is started by the database master process; The maintenance mode password generation module is used to perform the following: using the password entered when the database directory is initialized as the maintenance mode password, entering the maintenance mode password through the interactive interface returned by the database when the database is initialized, calculating the hash value of the maintenance mode password as a check value and storing it in the database directory; The maintenance mode password verification module is used to perform the following operations: when the maintenance mode is started, the password used when initializing the database directory is entered through the interactive interface returned by the database, the hash value of the entered password is calculated, and the generated hash value is compared with the checksum value. If they are the same, the verification is passed and the database can enter the maintenance mode; The maintenance mode startup module is used to perform the following: loading two specified template files when the database enters the maintenance mode, and if at least one of the template files is loaded successfully, the database enters the maintenance mode, wherein the two specified template files are initial form files formed after the database is initialized; The data playback module is used to perform the following operations: in maintenance mode, replay the data added by the user through the data playback tool; The operation audit module is used to perform the following operations: log the operation process of maintenance mode password generation, maintenance mode password verification, maintenance mode startup and data playback, store the recorded operation log in the audit log, and review it through the audit log after the database recovers from the abnormal state; Among them, data playback includes system data playback and user data playback; When replaying system data, the data replay module is used to perform the following operations: create a temporary system table, store the system table to be replayed in the temporary system table, and perform a connection test on the system table. If there is abnormal data in the original system table, read the abnormal system table line by line for the abnormal system table with abnormal data, and store the normal data in the abnormal system table in the temporary system table. When abnormal data is read, skip the abnormal data, record the location of the abnormal data in the abnormal log, and read the next line until the abnormal system table is finished reading. Then copy the data in the temporary system table to the normal table, and discard the data recorded in the abnormal log. The data file corresponding to the user data is a newly added physical file. When replaying the user data, the data replay module is used to replay the data by copying the user data physical file.
6. The database abnormal state repair system based on maintenance mode according to claim 5 is characterized in that: The maintenance mode password generation module is used to perform the following operations: When the database is initialized, an interactive interface for the maintenance mode password is returned through the database. The password entered when the database directory is initialized is entered through the interactive interface as the maintenance mode password; The maintenance mode password entered is checked for complexity. The complexity check rule is: the minimum length is 8 characters and must include uppercase and lowercase letters, numbers, and characters. Perform a hash calculation on the maintenance mode password that passes the complexity check. Use the user's local network card physical address (MAC address) as the key and hash the maintenance mode password using the HMAC SM3 hash algorithm. Store the resulting hash value as the check value in the MM.key file, which is then placed in the database's data directory, data. Correspondingly, the maintenance mode password verification module is used to perform the following operations: When starting the maintenance mode, the database returns an interactive interface for the maintenance mode password, and the password entered when the database directory was initialized is entered through the interactive interface; Using the user's local network card physical address MAC address as the key, the input password is hashed through the HMAC SM3 hash algorithm, and the generated hash value is compared with the check value in the MM.key file under the data directory data. If they are the same, the verification is passed and the database can enter maintenance mode, otherwise it exits.
7. The database abnormal state repair system based on maintenance mode according to claim 5 is characterized in that: During the maintenance mode startup process, after the database enters the maintenance mode, the maintenance mode startup module is used to close the network connection in the maintenance mode.
8. The database abnormal state repair system based on maintenance mode according to claim 5 is characterized in that: The data playback tool is the Database Playback tool.
Citation Information
Patent Citations
Method for initializing database based on dynamic password
CN102426592A
Graphical maintenance method and device for abnormal data, equipment and storage medium
CN113986907A