Backup Database Client Server

Database merupakan data yang sangat vital bagi sebuah sistem informasi, untuk memudahkan user dalam membackup database tersebut. maka diperlukan tools utuk mengcopi database tersebut. Berikut cara membuat backup database :

1.  Buat Form tampilan seperti Form di bawah ini :

2. Ketik/Copy source code untuk Form diatas, seperti berikut :

Option Explicit
Private Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10

Private Sub Command1_Click()
Dim apptorun As String
Dim parrform As String
Dim CmdLine As String
Dim answer As String
Dim X As Variant
Dim Y As Variant
For X = 0 To 23
If Check1(X).Value = Checked Then
Y = Check1(X).Caption & ” ” & Y
End If
apptorun = “c:\windows\system32\cmd.exe /c xcopy ”
parrform = Text1.Text & ” ” & Label2.Caption & ” ” & Y
CmdLine = apptorun & parrform ‘& “exit”

answer = MsgBox(“This will copy ” & Text1.Text & ” to ” & Label2.Caption, vbYesNo)
If answer = vbYes Then
Shell “cmd /c xcopy ” & Text1.Text & ” ” & Label2.Caption & ” ” & Y
MsgBox (“Database Telah Tercopy”)
End If
End Sub

Private Sub Dir2_Change()
Label2.Caption = Dir2.Path
End Sub

Private Sub Drive2_Change()
On Error GoTo handler
Dir2.Path = Drive2.Drive
Select Case Err.Number
Case 68
MsgBox “That Drive is not ready”, vbOKOnly, Error
End Select
End Sub

Private Sub Form_Load()
Drive2.Drive = “C:\”
Option1.Value = 1
End Sub

Private Sub Image1_Click()
On Error GoTo handler
Dim answer1 As Integer
Dim answer2 As String
answer1 = MsgBox(“This will create a new Directory in ” & Label2.Caption & “, do you want to continue?”, 4, “Create Directory”)
If answer1 = 6 Then
answer2 = InputBox(“Enter the name of the Directory”, “Create Directory”)
MkDir Label2.Caption & answer2
End If
Select Case Err.Number
Case 75
MsgBox “Direcory not created”, vbOKOnly, Error
End Select
End Sub

Private Sub mnuabout_Click()
frmAbout.Visible = True
End Sub

Public Sub ExecCmd(CmdLine As String)
Dim ReturnValue As Integer

‘//Initialize The STARTUPINFO Structure
start.cb = Len(start)

‘//Start The Shelled Application
ReturnValue = CreateProcessA(0&, CmdLine, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, Proc)

‘//Wait for The Shelled Application to Finish
ReturnValue = WaitForSingleObject(Proc.hProcess, 0)
Loop Until ReturnValue <> 258

‘//Close Handle to Shelled Application
ReturnValue = CloseHandle(Proc.hProcess)

End Sub
Private Sub CloseDosWindow(Optional Caption As Variant)
Dim hWnd As Long

‘ if argument is omitted, don’t care for window caption
If IsMissing(Caption) Then Caption = vbNullString

‘ find the window
hWnd = FindWindow(“ConsoleWindowClass”, Caption)
‘ close it by sending it a WM_CLOSE message
If hWnd Then
SendMessage hWnd, WM_CLOSE, 0, ByVal 0
End If
End Sub

Private Sub Option2_Click()
Dim info As Variant
If Option2.Value = True Then
info = MsgBox(“Masukan Alamat IP Database Server Contoh Pilih Database Inventaris”, vbInformation)
Text1.Text = “”
Text1.Text = “\\ ”
End If
End Sub

Keterangan :

Option1 = “Local”

Option2 = “Server”

Text1 = Isian untuk alamat IP

Command1 = “Back it up!”

3. Buat Modul baru dan ketik/copy sourcode di bawah ini :

Option Explicit

‘//public Constants
Public Const INFINITE = -1&

‘//public Types
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

‘//API Declarations
Public Declare Function WaitForSingleObject Lib “kernel32” (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Public Declare Function CreateProcessA Lib “kernel32” (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _

Public Declare Function CloseHandle Lib “kernel32” (ByVal _
hObject As Long) As Long

4. Isi default alamat database di local pada property text, misal :


5. Run (F5)

6. Pilih Source

7. pilih Destination/Letak Hasil Copy

8. Klik “Back it up!”

9. Selamat Mencoba..

Keterangan Untuk “xcopy” :

  • /w : Displays the following message and waits for your response before starting to copy files: Press any key to begin copying file(s)
  • /p : Prompts you to confirm whether you want to create each destination file.
  • /c : Ignores errors.
  • /v : Verifies each file as it is written to the destination file to make sure that the destination files are  identical to the source files.
  • /q : Suppresses the display of xcopy messages.
  • /f : Displays source and destination file names while copying.
  • /l : Displays a list of files that are to be copied.
  • /g : Creates decrypted destination files.
  • /d [:mm-dd-yyyy] :Copies source files changed on or after the specified date only. If you do not include a mm-dd-yyyy value, xcopy copies all Source files that are newer than existing Destination files. This command-line option allows you to update files that have changed.
  • /u : Copies files from Source that exist on Destination only.
  • /i : If Source is a directory or contains wildcards and Destination does not exist, xcopy assumes destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts you to specify whether Destination is a file or a directory.
  • /s : Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory.
  • /e : Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options.
  • /t : Copies the subdirectory structure (that is, the tree) only, not files. To copy empty directories, you must include the /e command-line option.
  • /k : Copies files and retains the read-only attribute on destination files if present on the source files. By default, xcopy removes the read-only attribute.
  • /r : Copies read-only files.
  • /h : Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files.
  • /a : Copies only source files that have their archive file attributes set. /a does not modify the archive file attribute of the source file. For information about how to set the archive file attribute by using attrib, see Related Topics.
  • /m : Copies source files that have their archive file attributes set. Unlike /a, /m turns off archive file attributes in the files that are specified in the source. For information about how to set the archive file attribute by using attrib, see Related Topics.
  • /n : Creates copies by using the NTFS short file or directory names. /n is required when you copy files or directories from an NTFS volume to a FAT volume or when the FAT file system naming convention (that is, 8.3 characters) is required on the destination file system. The destination file system can be FAT or NTFS.
  • /o : Copies file ownership and discretionary access control list (DACL) information.
  • /x : Copies file audit settings and system access control list (SACL) information (implies /o).
  • /y : Suppresses prompting to confirm that you want to overwrite an existing destination file.
  • /-y : Prompts to confirm that you want to overwrite an existing destination file.
  • /z : Copies over a network in restartable mode.


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:


You are commenting using your account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )


Connecting to %s

%d blogger menyukai ini: