top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What could be the Algorithm/s in database backup/s and restore programs ?. i.e. C/C++ Programming logic/Algorithm.

+3 votes
555 views

http://en.wikipedia.org/wiki/Relational_database_management_system

There are Database Backup and restore utilities for RDBMS Systems.
The Backup program generates a (.Bak) Binary File as output which can later be restored in case the Database crashes.

What could be the Algorithm/s in database backup/s and restore programs ?. i.e. C/C++ Programming logic/Algorithm.

posted Apr 25, 2014 by Balwinder

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

If you are asking me what algorithm can be used to backup a database but is written in C++. I do not know, but that would be reinventing the wheel anyway. You could think up an algorithm as well as I could that involved reading in all the data in the database into memory then writing that data to a binary flat file. If you are asking how to run a command that can be run on the command line in C++, then you can use the C++ ::system() function to run a command line command. The article below suggests this and the details of another method as well :

mysqldump -uroot -pmysql test> C/backup/test.sql

If I run the command above in command line, it will do a backup for my database "test"

Now, I tried to use the same command inside my Qt C++ code, but it did not work, while I can insert, delete and update my "test" database easily with no problems.

QSqlDatabase db; databaseConnection::openConnection(db); QSqlQuery queryBackup; queryBackup.prepare("mysqldump -uroot -pmysql test > C/backup/test2.sql" ); queryBackup.exec(); –

You need to use ::system() function to use mysqldump tool. You cannot create dump using SQL queries.

You can use QProcess class for this purpose too.

Here's an example:

QProcess dumpProcess(this);
QStringList args;
args << "-uroot" << "-pmysql" << "test";
dumpProcess.setStandardOutputFile("test.sql");
dumpProcess.start("mysqldump", args);

Note that your mysqldump tool should be in on any dir in PATH enviroment variable.

It is almost working perfectly, but the problem is that the code generates a test.sql file, but the file size is zero which means it does not connect to my MySQL database and copy the test database. Is there away to add IP address or something like this ? BTW.... I deleted "this" from the 1st line. Cause it gave an error.

this was for parent child relation. It's not important for this example. You need to familiarize yourself with mysqldump command. You need to use proper arguments to get a proper dump.

answer Apr 28, 2014 by Samardeep Acharya
...