快速业务通道

getSQLinfo.vbs 获得SQL数据/日志空间使用情况的脚本

作者 佚名 来源 ASP编程 浏览 发布时间 2013-07-09
获得SQL数据/日志空间使用,已使用的和未使用的空间的脚本

getSQLinfo.vbs
''scripttogetSQLDATA/LOGSpaceUsed,Spaceunused,
andSpaceFree
''Author:FelipeFerreira,DanielMagrini
''Date:05/07/07
''Version2,0

''@@TOCHANGE:::SERVERNAME\Instance,domain\user,passwordANDDATABSE!

''____________________________________________________________________________
ConstForReading=1,ForWriting=2,ForAppending=8
SetoFSO=CreateObject("Scripting.FilesyStemObject")
outputfile="CheckSqlDB_Size.txt"
Setofile=oFso.OpenTextFile(outputfile,8,True)
oFile.Writeline"######################################################"
oFile.Writeline"Thiscommandexecutedin"&Date&"at"&Time&VbCrLf
''____________________________________________________________________________

CheckSQLData
CheckSQLLOG


''##############GETSQLDATASPACEUSED,SPACETOTAL,SPACEFREE
''FunctioncheckSQL(strServer,strDB)inthefuturemakeitafunction....
SubCheckSQLDATA
ConstadOpenDynamic=1,adLockOptimistic=3
DimstrQuery
DimobjConnection,objRecordSet
DimstrQueryResult,strQueryResult2
DimUsedDataSpace,TotalDataSpace,FreeDataSpace
SetobjConnection=CreateObject("ADODB.Connection")
SetobjRecordSet=CreateObject("ADODB.Recordset")

objConnection.Open_
"Provider=SQLOLEDB.1;Server=192.168.8.10;UserID=sa;Password=lcx;Database=master;"

strQuery="DBCCshowfilestats"
objRecordSet.OpenstrQuery,objConnection,adOpenDynamic,adLockOptimistic
ifobjRecordSet.eofThen
''nothingreturned
wscript.echo"ERROR!!!"
Else

''NOTE:TogetthevalueinMB64/1024=0.0625
DoUntilobjRecordSet.eof
strQueryResult=objRecordSet.Fields("UsedExtents")
UsedDataSpace=strQueryResult*0.0625
strQueryResult2=objRecordSet.Fields("TotalExtents")
TotalDataSpace=strQueryResult2*0.0625
FreeDataSpace=TotalDataSpace-UsedDataSpace

''CleanData
UsedDataSpace=Left(UsedDataSpace,4)
FreeDataSpace=Left(FreeDataSpace,4)
TotalDataSpace=Left(TotalDataSpace,4)

''PrintResultonScreen
Wscript.echo"UsedSpace(MB)="&UsedDataSpace
Wscript.Echo"FreeSpace(MB)="&FreeDataSpace
Wscript.Echo"TotalSpace(MB)="&TotalDataSpace

''WriteonFile
ofile.WriteLine"UsedDATASpace(MB)="&UsedDataSpace
ofile.WriteLine"FreeDATASpace(MB)="&FreeDataSpace
ofile.WriteLine"TotalDATASpace(MB)="&TotalDataSpace

objRecordSet.MoveNext
loop
endif
objRecordSet.Close
objConnection.Close
setobjConnection=nothing
setobjRecordSet=nothing
endsub

SubCheckSQLLOG
ConstadOpenDynamic=1,adLockOptimistic=3
DimstrQuery
DimobjConnection,objRecordSet
DimstrQueryResult,strQueryResult2
DimUsedLogSpace,TotalLogSpace,FreeLogSpace
SetobjConnection=CreateObject("ADODB.Connection")
SetobjRecordSet=CreateObject("ADODB.Recordset")

objConnection.Open_
"Provider=SQLOLEDB.1;Server=192.168.8.10;UserID=sa;Password=lcx;Database=master;"

strQuery="DBCCSQLPERF(LOGSPACE)"
objRecordSet.OpenstrQuery,objConnection,adOpenDynamic,adLockOptimistic
ifobjRecordSet.eofThen
''nothingreturned
wscript.echo"ERROR!!!"
Else


DoUntilobjRecordSet.eof
IfobjRecordSet.Fields("DatabaseName")="master"Then


strQueryResult=objRecordSet.Fields("LogSize(MB)")
strQueryResult2=objRecordSet.Fields("LogSpaceUSed(

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号