MythTV
master
|
Aggregates database and DBMS utility functions. More...
#include <dbutil.h>
Public Member Functions | |
DBUtil ()=default | |
Constructs the DBUtil object. More... | |
~DBUtil ()=default | |
QString | GetDBMSVersion (void) |
Returns the QString version name of the DBMS or QString() in the event of an error. More... | |
int | CompareDBMSVersion (int major, int minor=0, int point=0) |
Compares the version of the active DBMS with the provided version. More... | |
Static Public Member Functions | |
static MythDBBackupStatus | BackupDB (QString &filename, bool disableRotation=false) |
Requests a backup of the database. More... | |
static bool | CheckTables (bool repair=false, const QString &options="QUICK") |
Checks database tables. More... | |
static bool | RepairTables (const QStringList &tables) |
Repairs database tables. More... | |
static bool | IsNewDatabase (void) |
Returns true for a new (empty) database. More... | |
static bool | IsBackupInProgress (void) |
Test to see if a DB backup is in progress. More... | |
static int | CountClients (void) |
Estimate the number of MythTV programs using the database. More... | |
static bool | TryLockSchema (MSqlQuery &query, uint timeout_secs) |
Try to get a lock on the table schemalock. More... | |
static void | UnlockSchema (MSqlQuery &query) |
static bool | CheckTimeZoneSupport (void) |
Check if MySQL has working timz zone support. More... | |
Static Public Attributes | |
static const int | kUnknownVersionNumber = INT_MIN |
Static Protected Member Functions | |
static bool | CreateTemporaryDBConf (const QString &privateinfo, QString &filename) |
Creates temporary file containing sensitive DB info. More... | |
Private Member Functions | |
bool | QueryDBMSVersion (void) |
Reads and returns the QString version name from the DBMS or returns QString() in the event of an error. More... | |
bool | ParseDBMSVersion (void) |
Parses m_versionString to find the major, minor, and point version. More... | |
Static Private Member Functions | |
static QStringList | GetTables (const QStringList &engines=QStringList()) |
Retrieves a list of tables from the database. More... | |
static QStringList | CheckRepairStatus (MSqlQuery &query) |
Parse the results of a CHECK TABLE or REPAIR TABLE run. More... | |
static QString | CreateBackupFilename (const QString &prefix="mythconverg", const QString &extension=".sql") |
Creates a filename to use for the filename. More... | |
static QString | GetBackupDirectory () |
Determines the appropriate path for the database backup. More... | |
static bool | DoBackup (const QString &backupScript, QString &filename, bool disableRotation=false) |
Creates a backup of the database by executing the backupScript. More... | |
static bool | DoBackup (QString &filename) |
Creates a backup of the database. More... | |
Private Attributes | |
QString | m_versionString |
int | m_versionMajor { -1 } |
int | m_versionMinor { -1 } |
int | m_versionPoint { -1 } |
Aggregates database and DBMS utility functions.
This class allows retrieving or comparing the DBMS server version, and backing up the database.
The backup functionality currently requires mysqldump to be installed on the system. This may change in the future to allow backups even when there is no DB client installation on the system.
|
default |
Constructs the DBUtil object.
|
default |
QString DBUtil::GetDBMSVersion | ( | void | ) |
Returns the QString version name of the DBMS or QString() in the event of an error.
Definition at line 38 of file dbutil.cpp.
Referenced by SchemaUpgradeWizard::PromptForUpgrade().
int DBUtil::CompareDBMSVersion | ( | int | major, |
int | minor = 0 , |
||
int | point = 0 |
||
) |
Compares the version of the active DBMS with the provided version.
Returns negative, 0, or positive if the active DBMS version is less than, equal to, or greater than the provided version or returns DBUtil::kUnknownVersionNumber if the version cannot be determined.
major | The major version number (i.e. 5 in "5.0.22") |
minor | The minor version number (i.e. 0 in "5.0.22") |
point | The point version number (i.e. 22 in "5.0.22") |
Definition at line 57 of file dbutil.cpp.
Referenced by SchemaUpgradeWizard::PromptForUpgrade().
|
static |
Requests a backup of the database.
If the DatabaseBackupScript exists in the ShareDir, it will be executed. All required database information will be made available as name=value pairs in a temporary file whose filename will be passed to the backup script. The script may parse this file to obtain the required information to run a backup program, such as mysqldump or mysqlhotcopy.
If the DatabaseBackupScript does not exist, a backup will be performed using mysqldump directly. The database password will be passed in a temporary file so it does not have to be specified on the command line.
Care should be taken in calling this function. It has the potential to corrupt in-progress recordings or interfere with playback.
The disableRotation argument should be used only for automatic backups when users could lose important backup files due to a failure loop–for example, a DB upgrade failure and a distro start script that keeps restarting mythbackend even when it exits with an error status.
filename | Used to return the name of the resulting backup file |
disableRotation | Disable backup rotation |
Definition at line 190 of file dbutil.cpp.
Referenced by Myth::BackupDatabase(), V2Myth::BackupDatabase(), and SchemaUpgradeWizard::BackupDB().
Checks database tables.
This function will check database tables.
repair | Repair any tables whose status is not OK |
options | Options to be passed to CHECK TABLE; defaults to QUICK |
Definition at line 279 of file dbutil.cpp.
Referenced by Myth::CheckDatabase(), and V2Myth::CheckDatabase().
|
static |
Repairs database tables.
This function will repair MyISAM database tables.
Care should be taken in calling this function. It should only be called when no clients are accessing the database, and in the event the MySQL server crashes, it is critical that a REPAIR TABLE is run on the table that was being processed at the time of the server crash before any other operations are performed on that table, or the table may be destroyed. It is up to the caller of this function to guarantee the safety of performing database repairs.
tables | List of tables to repair |
Definition at line 337 of file dbutil.cpp.
Referenced by CheckTables().
|
static |
Returns true for a new (empty) database.
Definition at line 78 of file dbutil.cpp.
Referenced by BackupDB(), SchemaUpgradeWizard::Compare(), and doUpgradeTVDatabaseSchema().
|
static |
Test to see if a DB backup is in progress.
Definition at line 92 of file dbutil.cpp.
|
static |
Estimate the number of MythTV programs using the database.
Definition at line 806 of file dbutil.cpp.
Referenced by SchemaUpgradeWizard::PromptForUpgrade().
Try to get a lock on the table schemalock.
Prevents multiple upgrades by different programs of the same schema.
Definition at line 848 of file dbutil.cpp.
Referenced by UpgradeMusicDatabaseSchema(), and UpgradeTVDatabaseSchema().
|
static |
Definition at line 855 of file dbutil.cpp.
Referenced by UpgradeMusicDatabaseSchema(), and UpgradeTVDatabaseSchema().
|
static |
Check if MySQL has working timz zone support.
Definition at line 867 of file dbutil.cpp.
Referenced by V2Myth::GetBackendInfo(), main(), and run_backend().
|
staticprotected |
Creates temporary file containing sensitive DB info.
So we don't have to specify the password on the command line, use –defaults-extra-file to specify a temporary file with a [client] and [mysqldump] section that provides the password. This will fail if the user's ~/.my.cnf (which is read after the –defaults-extra-file) specifies a different password that's incorrect for dbUserName
Definition at line 523 of file dbutil.cpp.
Referenced by DoBackup().
|
private |
Reads and returns the QString version name from the DBMS or returns QString() in the event of an error.
Definition at line 753 of file dbutil.cpp.
Referenced by GetDBMSVersion(), and ParseDBMSVersion().
|
private |
Parses m_versionString to find the major, minor, and point version.
Definition at line 782 of file dbutil.cpp.
Referenced by CompareDBMSVersion().
|
staticprivate |
Retrieves a list of tables from the database.
Definition at line 428 of file dbutil.cpp.
Referenced by CheckTables(), and IsNewDatabase().
|
staticprivate |
Parse the results of a CHECK TABLE or REPAIR TABLE run.
This function reads the records returned by a CHECK TABLE or REPAIR TABLE run and determines the status of the table(s). The query should have columns Table, Msg_type, and Msg_text.
The function properly handles multiple records for a single table. If the last record for a given table shows a status (Msg_type) of OK (Msg_text), the table is considered OK, even if an error or warning appeared before (this could be the case, for example, when an empty table is crashed).
query | An already-executed CHECK TABLE or REPAIR TABLE query whose results should be parsed. |
Definition at line 384 of file dbutil.cpp.
Referenced by CheckTables(), and RepairTables().
|
staticprivate |
Creates a filename to use for the filename.
The filename is a concatenation of the given prefix, a hyphen, the current date/time, and the extension.
prefix | The prefix (i.e. a database name) which should appear before the date/time |
extension | The extension to use for the file, including a dot, if desired |
Definition at line 471 of file dbutil.cpp.
Referenced by DoBackup().
|
staticprivate |
Determines the appropriate path for the database backup.
The function requests the special "DB Backups" storage group. In the event the group is not defined, the StorageGroup will fall back to using the "Default" group. For users upgrading from version 0.20 or before (which do not support Storage Groups), the StorageGroup will fall back to using the old RecordFilePrefix.
Definition at line 486 of file dbutil.cpp.
Referenced by DoBackup().
|
staticprivate |
Creates a backup of the database by executing the backupScript.
This function executes the specified backup script to create a database backup. This is the preferred approach for creating the backup.
Definition at line 567 of file dbutil.cpp.
Referenced by BackupDB().
|
staticprivate |
Creates a backup of the database.
This fallback function is used only if the database backup script cannot be found.
Definition at line 664 of file dbutil.cpp.
|
static |
Definition at line 57 of file dbutil.h.
Referenced by CompareDBMSVersion().
|
private |
Definition at line 78 of file dbutil.h.
Referenced by GetDBMSVersion(), ParseDBMSVersion(), and QueryDBMSVersion().
|
private |
Definition at line 80 of file dbutil.h.
Referenced by CompareDBMSVersion(), and ParseDBMSVersion().
|
private |
Definition at line 81 of file dbutil.h.
Referenced by CompareDBMSVersion(), and ParseDBMSVersion().
|
private |
Definition at line 82 of file dbutil.h.
Referenced by CompareDBMSVersion(), and ParseDBMSVersion().