'***************************************************************************************************
' SQL DMO, File SystemObject, shell을 이용 Database Object별 Secript 생성
' Argument 설명
' arg 0 : saveRoot dir(local 또는 Unc)
' arg 1 : database Login Id
' arg 2 : database Login Pwd
' arg 3 : server name, server IP
' arg 4 : scripting을 할 데이터베이스 네임
'
' Run Example ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' prompt:\>cscript script.vbs "c:\script\" "<id>" "<pwd>" "<Server>" "<databasename>"
' 확인 : c:\script
'***************************************************************************************************
'변수들에 대한 개체 정의
Dim objArgs, objSql, fso, WshShell, objDb, dbName
Dim ScriptDb, saveDir
' SQL DMO, File SystemObject, shell을 이용 Database Object별 Secript 생성
' Argument 설명
' arg 0 : saveRoot dir(local 또는 Unc)
' arg 1 : database Login Id
' arg 2 : database Login Pwd
' arg 3 : server name, server IP
' arg 4 : scripting을 할 데이터베이스 네임
'
' Run Example ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' prompt:\>cscript script.vbs "c:\script\" "<id>" "<pwd>" "<Server>" "<databasename>"
' 확인 : c:\script
'***************************************************************************************************
'변수들에 대한 개체 정의
Dim objArgs, objSql, fso, WshShell, objDb, dbName
Dim ScriptDb, saveDir
Set objSQL = CreateObject("SQLDMO.SQLServer")
Set fso = CreateObject ("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject ("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set objArgs = Wscript.Arguments
saveDir = objArgs(0)
objSQL.LoginSecure = False 'Trust된 곳이라면 당연히 True가 되면서 Login pwd불필요
objSQL.Login = objArgs(1)
objSQL.Password = objArgs(2)
objSQL.Login = objArgs(1)
objSQL.Password = objArgs(2)
'Server Connect
objSQL.Connect objArgs(3)
objSQL.Connect objArgs(3)
Set objDB = objSQL.Databases
If Not(fso.FolderExists(saveDir)) Then
createFolder saveDir
End If
createFolder saveDir
End If
scriptDb = objArgs(4)
If NOT(fso.FolderExists(saveDir & scriptDb)) Then
createFolder saveDir & scriptDb
End If
createFolder saveDir & scriptDb
End If
''''여기서 부터 개체 콜하기 시작
For each dbName in objDB
If LCase(dbName.name) = LCase(scriptDb) Then
ScriptOut dbName.tables, "Tables"
ScriptOut dbName.StoredProcedures, "StoredProcs"
ScriptOut dbName.Views, "Views"
ScriptOut dbName.Users, "Users"
ScriptOut dbName.Rules, "Rules"
ScriptOut dbName.UserDefinedDatatypes, "UserDefDataType"
ScriptOut dbName.UserDefinedFunctions, "UserDefFunc"
For each dbName in objDB
If LCase(dbName.name) = LCase(scriptDb) Then
ScriptOut dbName.tables, "Tables"
ScriptOut dbName.StoredProcedures, "StoredProcs"
ScriptOut dbName.Views, "Views"
ScriptOut dbName.Users, "Users"
ScriptOut dbName.Rules, "Rules"
ScriptOut dbName.UserDefinedDatatypes, "UserDefDataType"
ScriptOut dbName.UserDefinedFunctions, "UserDefFunc"
End If
Next
Next
''''이놈은 파일을 만들 sub proc
Sub ScriptOut(object, foldername)
For each item in object
If item.SystemObject = False Then
createFolder saveDir & scriptDb & "\" & foldername
sFileName = saveDir & scriptDb & "\" & foldername & "\" & Replace(item.Name, "\", "-") & ".sql"
' MsgBox item.Script
If IsNull(item.script) Or IsEmpty(item.script) Then
Else
If IsNull(sFileName) Or IsEmpty(sFileName) Then
Else
item.Script 4, sFileName
End If
End If
End If
Next
End Sub
Sub ScriptOut(object, foldername)
For each item in object
If item.SystemObject = False Then
createFolder saveDir & scriptDb & "\" & foldername
sFileName = saveDir & scriptDb & "\" & foldername & "\" & Replace(item.Name, "\", "-") & ".sql"
' MsgBox item.Script
If IsNull(item.script) Or IsEmpty(item.script) Then
Else
If IsNull(sFileName) Or IsEmpty(sFileName) Then
Else
item.Script 4, sFileName
End If
End If
End If
Next
End Sub
''''이놈은 폴더를 만들 sub proc 'fso의 약간의 버그로 인한..
Sub createFolder(fName)
If NOT(fso.FolderExists(fName)) Then
WshShell.Run "cmd /c md " & fName
WScript.Sleep 1000
End If
End Sub
Sub createFolder(fName)
If NOT(fso.FolderExists(fName)) Then
WshShell.Run "cmd /c md " & fName
WScript.Sleep 1000
End If
End Sub
'Databases' 카테고리의 다른 글
MySQL SELECT 결과의 출력물 제어(pager) - 페이지 단위로 끊어서 보기 (0) | 2011.04.27 |
---|---|
MySQL 전체 백업 (0) | 2011.04.27 |
MYSQL 테이블 데이타 사이즈 (0) | 2011.04.19 |
mssql 테이블 복사 쿼리 (2) | 2011.04.18 |
Join의 모든것.(LEFT OUTER, RIGHT OUTER, INNER, FULL OUTER, CROSS) (0) | 2011.04.13 |