WinAPI'de ShellExecuteEx() fonksiyonu ile MySQL veri yedekleme (backup)
MySQL'de veritabanını üzerinde yedekleme (backup) işlemlerini mysqldump.exe programı ve yedeklenen veriyi yeniden yükleme işlemlerini mysql.exe programı ile komut satırında yapmak istediğinizde aşağıdaki ifadeleri kullanabilirsiniz:
MySQL Sunucunun kurulu olduğu dizinin "C:\Program Files\MySQL\MySQL Server 5.5\bin" olduğu varsayılarak:
Aşağıdaki komut dbase_adi adlı veritabanının yedeğini C: sürücüsündeki yedek klasörü altına veri.sql dosyası adı ile alır:
C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump.exe --port=3306 -u root -pparola dbase_adi --result-file C:\yedek\veri.sql
Aşağıdaki komut C: sürücüsündeki yedek klasörü altında bulunan veri.sql dosyasındaki verileri dbase_adi adlı veritabanına aktarır:
C:\Program Files\MySQL\MySQL Server 5.5\bin>mysql.exe --database=dbase_adi --port=3306 -u root -pparola < C:\yedek\veri.sql
Aynı işlemi, işlem pencerelerini ekranda göstermeden, C programlama dilinde WinAPI komutları gerçekleştirmek için aşağıdaki satırları kullanabilirsiniz:
VeriYedYuk(0); /* Veritabanını yedekleme (backup) */ VeriYedYuk(1); /* Veritabanını geri yükleme */ BOOL VeriYedYuk(int islem) { SHELLEXECUTEINFO shellexecuteinfo; char cpath[4096]; DWORD retval = 0; DWORD dwExitCode = 0; char cdizi[1000]; ZeroMemory( &shellexecuteinfo, sizeof(SHELLEXECUTEINFO)); shellexecuteinfo.cbSize = sizeof(SHELLEXECUTEINFO); shellexecuteinfo.fMask = SEE_MASK_NOCLOSEPROCESS; shellexecuteinfo.hwnd = hwndPanelFat; shellexecuteinfo.lpVerb = "open"; if (islem==0) { shellexecuteinfo.lpFile = "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe"; shellexecuteinfo.lpParameters = "--port=3306 -u root -pparola dbase_adi --result-file C:\yedek\veri.sql"; } else { retval = GetShortPathName("C:\Program Files\MySQL\MySQL Server 5.5\bin", cpath, 4096); if (retval == 0) { return 0; } shellexecuteinfo.lpFile = "cmd.exe"; sprintf (cdizi, "/C %s\mysql.exe --database=dbase_adi --port=3306 -u root -pparola < C:\yedek\veri.sql", cpath); shellexecuteinfo.lpParameters = cdizi; } shellexecuteinfo.lpDirectory = NULL; shellexecuteinfo.nShow = SW_HIDE; shellexecuteinfo.hInstApp = NULL; if (ShellExecuteEx(&shellexecuteinfo)) { if (shellexecuteinfo.hProcess != NULL) { WaitForSingleObject(shellexecuteinfo.hProcess, INFINITE); if (GetExitCodeProcess(shellexecuteinfo.hProcess, &dwExitCode)) { if (dwExitCode) { return 0; } CloseHandle(shellexecuteinfo.hProcess); } else { MessageBox(NULL, "GetExitCodeProcess() fonksiyon hatası", "Fonksiyon hatası", MB_OK | MB_ICONWARNING); } CloseHandle(shellexecuteinfo.hProcess); } } else { MessageBox(NULL, "ShellExecuteEx() fonksiyon hatası", "Fonksiyon hatası", MB_OK | MB_ICONWARNING); return 0; } return 1; }