getSQLinfo.vbs 获得SQL数据/日志空间使用情况的脚本
获得SQL数据/日志空间使用,已使用的和未使用的空间的脚本
getSQLinfo.vbs
'script to get SQL DATA/LOG Space Used, Space unused,
and Space Free
'Author: Felipe Ferreira, Daniel Magrini
'Date: 05/07/07
'Version 2,0
'@@TO CHANGE::: SERVERNAME\Instance, domain\user, password AND DATABSE!
'____________________________________________________________________________
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set oFSO = CreateObject("Scripting.FilesyStemObject")
outputfile = "CheckSqlDB_Size.txt"
Set ofile = oFso.OpenTextFile(outputfile,8, True)
oFile.Writeline "######################################################"
oFile.Writeline "This command executed in " & Date & " at " & Time & VbCrLf
'____________________________________________________________________________
CheckSQLData
CheckSQLLOG
'############## GET SQL DATA SPACE USED, SPACE TOTAL, SPACE FREE
'Function checkSQL(strServer,strDB) in the future make it a function....
Sub CheckSQLDATA
Const adOpenDynamic = 1, adLockOptimistic = 3
Dim strQuery
Dim objConnection, objRecordSet
Dim strQueryResult, strQueryResult2
Dim UsedDataSpace, TotalDataSpace, FreeDataSpace
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open _
"Provider=SQLOLEDB.1;Server=192.168.8.10;User ID=sa;Password=lcx;Database=master;"
strQuery = "DBCC showfilestats"
objRecordSet.Open strQuery, objConnection, adOpenDynamic, adLockOptimistic
if objRecordSet.eof Then
'nothing returned
wscript.echo "ERROR!!!"
Else
'NOTE : To get the value in MB 64 / 1024 = 0.0625
Do Until objRecordSet.eof
strQueryResult = objRecordSet.Fields("UsedExtents")
UsedDataSpace = strQueryResult * 0.0625
strQueryResult2 = objRecordSet.Fields("TotalExtents")
TotalDataSpace = strQueryResult2 * 0.0625
FreeDataSpace = TotalDataSpace - UsedDataSpace
'Clean Data
UsedDataSpace = Left(UsedDataSpace,4)
FreeDataSpace = Left(FreeDataSpace,4)
TotalDataSpace = Left(TotalDataSpace,4)
'Print Result on Screen
Wscript.echo "Used Space(MB) = " & UsedDataSpace
Wscript.Echo "Free Space(MB) = " & FreeDataSpace
Wscript.Echo "Total Space(MB) = " & TotalDataSpace
'Write on File
ofile.WriteLine "Used DATA Space(MB) = " & UsedDataSpace
ofile.WriteLine "Free DATA Space(MB) = " & FreeDataSpace
ofile.WriteLine "Total DATA Space(MB) = " & TotalDataSpace
objRecordSet.MoveNext
loop
end if
objRecordSet.Close
objConnection.Close
set objConnection = nothing
set objRecordSet = nothing
end sub
Sub CheckSQLLOG
Const adOpenDynamic = 1, adLockOptimistic = 3
Dim strQuery
Dim objConnection, objRecordSet
Dim strQueryResult, strQueryResult2
Dim UsedLogSpace, TotalLogSpace, FreeLogSpace
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open _
"Provider=SQLOLEDB.1;Server=192.168.8.10;User ID=sa;Password=lcx;Database=master;"
strQuery = "DBCC SQLPERF(LOGSPACE)"
objRecordSet.Open strQuery, objConnection, adOpenDynamic, adLockOptimistic
if objRecordSet.eof Then
'nothing returned
wscript.echo "ERROR!!!"
Else
Do Until objRecordSet.eof
If objRecordSet.Fields("Database Name") = "master" Then
strQueryResult = objRecordSet.Fields("Log Size (MB)")
strQueryResult2 = objRecordSet.Fields("Log Space USed (%)")
UsedLogSpace = (strQueryResult * strQueryResult2) / 100
TotalLogSpace = strQueryResult
FreeLogSpace = TotalLogSpace - UsedLogSpace
'Clean Data
UsedLogSpace = Left(UsedLogSpace,4)
FreeLogSpace = Left(FreeLogSpace,4)
TotalLogSpace = Left(TotalLogSpace,4)
'Print Result on Screen
Wscript.echo "Used Space(MB) = " & UsedLogSpace
Wscript.Echo "Free Space(MB) = " & FreeLogSpace
Wscript.Echo "Total Space(MB) = " & TotalLogSpace
'Write on File
oFile.WriteLine "Used LOG Space(MB) = " & UsedLogSpace
oFile.WriteLine "Free LOG Space(MB) = " & FreeLogSpace
oFile.WriteLine "Total LOG Space(MB) = " & TotalLogSpace
oFile.close
Exit Do
End If
objRecordSet.MoveNext
loop
end if
objRecordSet.Close
objConnection.Close
set objConnection = nothing
set objRecordSet = nothing
end sub
WSCript.Quit
您可能感兴趣的文章
- 01-10防SQL注入的VBSrcipt代码
- 01-10dvbbs 8.2 SQL Injection注射漏洞分析
- 01-10VBS如何察看或获得剪切板内容的脚本
- 01-10利用sql语句复制一条或多条记录
- 01-10vbs版sql查询分析器lcx作品
- 01-10查看SQL状态的vbs
- 01-10SQLids.vbs 0.7(最终版,以后改成gui界面的)
- 01-10SQL获取表结构的show
- 01-10如何用word vb宏来生成sql
- 01-10使用vbs获得外网ip并发送到邮箱里
阅读排行
本栏相关
- 01-10下载文件到本地运行的vbs
- 01-10飘叶千夫指源代码,又称qq刷屏器
- 01-10SendKeys参考文档
- 01-10什么是一个高效的软件
- 01-10VBS中的正则表达式的用法大全 &l
- 01-10exe2swf 工具(Adodb.Stream版)
- 01-10VBS中SendKeys的基本应用
- 01-10用VBSCRIPT控制ONSUBMIT事件
- 01-10VBScript教程 第十一课深入VBScript
- 01-10VBScript语法速查及实例说明
随机阅读
- 01-10delphi制作wav文件的方法
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 01-11ajax实现页面的局部加载
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 04-02jquery与jsp,用jquery
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 01-10SublimeText编译C开发环境设置
- 01-10C#中split用法实例总结