Cari Blog Ini

21 Desember 2011

VB Script for Backup in Multiple Task

Save the code below, as "Backup_Code_Database_Portal.vbs"
Then double-click the file, to get 2 results example :
1. "BackupDBPortal_2011-09-29-17-00-00.bak"
2. "Portal_2011-09-29-17-00-00.zip"


'--------------------------------------------------------------------------------
'-----code start
'--------------------------------------------------------------------------------

OPTION EXPLICIT
dim ws, MyStr(100), i, MyTimeStamp, MyFileName1, MyFileName2 
dim q



MyTimeStamp = cstr(year(now)) & "-" & _
    right(cstr(100+month(now)),2) & "-" & _
    right(cstr(100+day(now)),2) & "-" & _
    right(cstr(100+hour(now)),2) & "-" & _
    right(cstr(100+minute(now)),2) & "-" & _
    right(cstr(100+second(now)),2)


Set ws = WScript.CreateObject("WScript.Shell")

MyFileName1 ="'C:\BackUpPortal\BackupDBPortal_" & MyTimeStamp  & ".bak'"
MyFileName2 ="C:\BackUpPortal\Portal_" & MyTimeStamp  & ".zip"

MyStr(1)="sqlcmd -S ""SERVER01"" -d ""dotnetnuke"" -U ""sa"" -P ""sasasa"" -Q ""BACKUP DATABASE dotnetnuke TO DISK =" & MyFileName1 & """  "
MyStr(2)="""cmd.exe"" /c c:\BackUpPortal\zip.exe -r " & _
    """" & MyFileName2 & """ " & _
    """c:\Portal\*.*"" "

ws.run MyStr(1)
ws.run MyStr(2)

'--------------------------------------------------------------------------------
'-----code end
'--------------------------------------------------------------------------------