Guide and Sample Codes of Using V1.2

MySqlBackup 1.2 will be released on 20 June 2012 (Wednesday).
V1.2 is a revised and enhanced version based on V1.1.
This release will not affect the development of V2.0. (Release in August 2012)

We start using MySqlBackup 1.2 by adding a reference of MySqlBackup.dll to your project.

01.png

02.png

Note: We are using MySql.Data.dll (MySQL ADO.NET Connector) version 6.5.4.0 (which is the latest at this time) to compile this tool. If you are using other version of MySql.Data.dll, you have to manually recompile MySqlBackup.dll with your version of MySql.Data.dll.

At the top of your project add this line:
using MySql.Data.MySqlClient;

Below are the examples of using the tool.

1. Backup MySQL database. (Export)
private void Backup()
{
    string sqlDumpFile = "C:\\backup.sql";
    string con = "server=localhost;user=root;pwd=1234;database=member;";
    MySqlBackup mb = new MySqlBackup(con);
    mb.Export(sqlDumpFile);
}

2. Restore MySQL database (Import)
private void Restore()
{
    string sqlDumpFile = "C:\\backup.sql";
    string con = "server=localhost;user=root;pwd=1234;database=member;";
    MySqlBackup mb = new MySqlBackup(con);
    mb.Import(sqlDumpFile);
}

3. Select tables to backup.
private void BackupCustomTable()
{
    string[] tables = new string[3];
    tables[0] = "member";
    tables[1] = "payment";
    tables[2] = "activity";
    string sqlDumpFile = "C:\\backup.sql";
    string con = "server=localhost;user=root;pwd=1234;database=member;";
    MySqlBackup mb = new MySqlBackup(con);
    mb.Export(sqlDumpFile, tables);
}

4. Custom columns and rows backup conditions.
private void BackupCustomColumnsRows()
{
    Dictionary<string, string> dic = new Dictionary<string, string>();
    dic.Add("member", "SELECT * FROM `member` WHERE `membertype` = 1;");
    dic.Add("payment", "SELECT `id`,`total` FROM `payment`;");
    dic.Add("activity", "SELECT * FROM `activity` a INNER JOIN `season` s ON a.`seasonid` = s.`id` WHERE s.`name` = 'Spring';");
    string sqlDumpFile = "C:\\backup.sql";
    string con = "server=localhost;user=root;pwd=1234;database=member;";
    MySqlBackup mb = new MySqlBackup(con);
    mb.Export(sqlDumpFile, dic);
}

5. Backup with Encryption.
private void BackupEncrypt()
{
    string sqlDumpFile = "C:\\backup.sql";
    string con = "server=localhost;user=root;pwd=1234;database=member;";
    MySqlBackup mb = new MySqlBackup(con);
    mb.EnableEncryption = true;
    mb.EncryptionKey = "qwerty";
    mb.Export(sqlDumpFile);
}

6. Restore with Decryption.
private void RestoreDecrypt()
{
    string sqlDumpFile = "C:\\backup.sql";
    string con = "server=localhost;user=root;pwd=1234;database=member;";
    MySqlBackup mb = new MySqlBackup(con);
    mb.EnableEncryption = true;
    mb.EncryptionKey = "qwerty";
    mb.Import(sqlDumpFile);
}

7. Encrypt the Dump File.
private void EncryptDumpFile()
{
    string oldDumpFile = "C:\\backup.sql";
    string newDumpFile = "C:\\backup_new.sql";
    MySqlBackup mb = new MySqlBackup();
    mb.EnableEncryption = true;
    mb.EncryptionKey = "qwerty";
    mb.EncryptSqlDumpFile(oldDumpFile, newDumpFile);
}

8. Decrypt the Dump File.
private void DecryptDumpFile()
{
    string oldDumpFile = "C:\\backup.sql";
    string newDumpFile = "C:\\backup_new.sql";
    MySqlBackup mb = new MySqlBackup();
    mb.EnableEncryption = true;
    mb.EncryptionKey = "qwerty";
    mb.DecryptSqlDumpFile(oldDumpFile, newDumpFile);
}

9. Other Available Settings

Features (1.2):

Changes from V1.1 to V1.2 Thanks you to everyone for the codes, patches, suggestion, ideas, comments, bugs report and more. V1.2 is actually a part of the development of V2.0. We look forward for the birth of V2.0 which is under construction.

Currently, source code of V1.2 can be download at the change set of 50fa82416434, or at [Download] after it is released.