Untuk proses backup kita cukup menggunakan tool bawaan MySQL yaitu mysqldump dan untuk restorenya menggunakan mysql.
Adapun perintah dasar untuk melakukan backup dan restore adalah sebagai berikut :
2 | mysqldump -uUSER_NAME -pUSER_PASSWORD --routines NAMA_DATABASE > LOKASI_FILE_BACKUP.SQL |
5 | mysql -uUSER_NAME -pUSER_PASSWORD NAMA_DATABASE < LOKASI_FILE_BACKUP.SQL |
parameter –routines ditambahkan jika database mempunyai fungsi/trigger
Sekarang tinggal kita siapkan kode berikut :
01 | Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long |
02 | Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long |
03 | Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long |
05 | Private Const SYNCHRONIZE As Long = &H 100000 |
06 | Private Const INFINITE As Long = &HFFFF |
08 | Private Sub execCommand(ByVal cmd As String) |
15 | result = Shell(cmd, vbHide) |
19 | lHnd = OpenProcess(SYNCHRONIZE, 0 , lPid) |
21 | lRet = WaitForSingleObject(lHnd, INFINITE) |
kemudian tinggal panggil di masing-masing proses (backup dan restore)
03 | Private Sub cmdBackup_Click() |
04 | Screen.MousePointer = vbHourglass |
07 | cmd = Chr( 34 ) & "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump" & Chr( 34 ) & " -uroot -prahasia --routines --comments nama_database > c:\nama_database.sql" |
10 | Screen.MousePointer = vbDefault |
14 | Private Sub cmdRestore_Click() |
15 | Screen.MousePointer = vbHourglass |
18 | cmd = Chr( 34 ) & "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql" & Chr( 34 ) & " -uroot -prahasia --comments nama_database < c:\nama_database.sql" |
21 | Screen.MousePointer = vbDefault |
kode diatas dengan asumsi direktori bin MySQL ada di folder “C:\Program Files\MySQL\MySQL Server 5.1\bin”.
Selamat mencoba sumber
0 comments:
Posting Komentar