清理系统中的垃圾文件
作者:Shawn Penner,现就职于SAP
原文地址(英语):
过去的时间里,已经有一些问题和漏洞会在产生垃圾文件,存放于输入/输出文件资源服务器上(FRS)。这个页面里的脚本旨在创建一个清理FRS服务器的工具,来保证不产生多余的文件来占用空间。
所有的这些脚本都是用VBScript编写的,而且为了BOE XI R2设计,但是一般来讲,它们也会在BOE XI R3上面生效。(尽管他们在BOE XI R3上不被支持)
注意:
更多其他的脚本和信息,关于如何运行脚本,可以在这里找到:
扫描和清理FRS服务器
这个脚本将会对输入和输出的FRS里面无响应的文件进行扫描,并且删除它们。它同样会删除文件移除后残留的文件夹。它运作的方法是,如果一个相对应的InfoObject存在,假设最低级别的文件夹名字就是这个对象的SI_ID。如果这个有SI_ID的对象存在于Enterprise Server里面,那么这个对象就被假定为有效。
注意事项:
- 您需要将用户名,密码,CMS名字都改成特别对应于您的企业服务器的值。强烈建议您使用管理员账户,因为其他用户可能不会看到所有企业服务器上面的对象。而且如果脚本看不到对象,它就会假设它不存在,然后删除符合的文件。
- 这个脚本会创建一个日志文件,位于“C:\output.log” 来储存脚本运行的结果。
- 为了在测试模式下运行这个脚本,把DoDelete变量设置为false。要是想脱离测试模式,把DoDelete变量设置为true。
- 这个脚本必须在FRS实际存放的服务器上运行,或者那里有一个直接的路径通到FRS文件夹。
- 你将会需要把输出和输入FRS改成根目录。
XI R2的默认位置:
“C:\Program Files\Business Objects\BusinessObjects Enterprise 11.5\FileStore\Input”
“C:\Program Files\Business Objects\BusinessObjects Enterprise 11.5\FileStore\Output”
XI R3的默认位置:
“C:\Program Files (x86)\Business Objects\BusinessObjects Enterprise 12.0\FileStore\Input”
“C:\Program Files (x86)\Business Objects\BusinessObjects Enterprise 12.0\FileStore\Output”
- 输入和输出的FRS的路径必须不能在结尾加入斜线,否则脚本会失效。
- 如果你在一个64位操作系统例如Windows 7上运行该脚本,你会需要检验这个脚本的32位版本是否能够运行。否则你会遇到报错: “ActiveX component can’t create object: ‘CrystalEnterprise.SessionMgr’ “
例如:%windir%\SysWOW64\cscript.exe scanfrs.vbs
扫描和清理FRS服务器 |
---|
Dim DoDelete DoDelete = False ‘ False = Test Mode, True = Actually Delete the Files ‘Declare CMS logon variables CMS = “localhost” ‘Declare variables for Enterprise Session ‘ File IO stuff ‘Open the outputFile for logging. outputFile.WriteLine(“——– Starting Script ——–“) ‘Load the Enterprise Session Manager ‘Logon to the CMS and create iStore object outputFile.WriteLine(“Input FRS Root = ” & inputFRSRoot) ‘ Now that we have the root folders – we need to loop through them and drill down to the deepest level Dim finalOutput ‘ Scan the Input FRS ‘ Scan the Output FRS outputFile.WriteLine(“All Done”) ‘ Clean everything up Function CheckAndDelete(DoDelete, iStore, objFSO, outputFile, fileRoot) ‘ Set it initially to not delete the folder Set boFolder = objFSO.GetFolder(fileRoot) ‘ Get a count of the files in this folder, and a count of the sub-folders ‘ Are there files here – then we need to check if the matching SI_ID exists ‘ If the count is 0 – then this is an orphan ‘ Set the delete flag to true to tell the function one up the recursive stack to remove this folder For Each boSubFolder in boFolder.SubFolders |
解析RepoScan XML
接下来的脚本实际上没有使用BusinessObjects的SDK来清理输入和输出FRS。相反它利用了RepoScan工具来鉴定CMS数据库和磁盘上存放的不匹配情况。
注意事项:
- 你需要运行RepoScan工具来生成一个日志文件。为了运行RepoScan,参照如下步骤:
·创建一个options.txt文件,我已经把一个示例贴在下面:
-dbdriver mysqldatabasesubsystem
-inputfrsdir “C:\Program Files\Business Objects\BusinessObjects Enterprise 12.0\FileStore\Input”
-outputfrsdir “C:\Program Files\Business Objects\BusinessObjects Enterprise 12.0\FileStore\Output”
-connect UID=sa;PWD=bopassword123;DSN=BOE120;HOSTNAME=MyEnterpriseServer;
-outputdir c:\
-repair false
上面的这些选项鉴别了:文件使用的什么数据库,输入和输出FRS保存位置,数据库连接字符串,生成的日志文件存放在哪里,是否要尝试和修复问题。
·一旦你生成了options.txt 文件,到下面的目录 C:\Program Files\Business Objects\BusinessObjects Enterprise 12.0\win32_x86 (For BOE XI R2)执行命令:
reposcan -optionsfile c:\options.txt
c:\options.txt就是配置文件所在的位置。
·这回生成一个日志文件,名为 “Repo_Scan_<Date and Time>.xml”,它会生成在上面特定的输出目录下(在这里是C:\)。
- 你会需要在脚本里面更改文件的路径,改成被RepoScan生成的xml文件位置。
- 如果你在一个64位操作系统例如Windows 7上运行这个脚本,你会需要检验这个脚本的32位版本是否能够运行。否则你会遇到报错:“ActiveX component can’t create object: ‘Scripting.FileSystemObject’ “
例如:%windir%\SysWOW64\cscript reposcanxmlparser.vbs
解析RepoScan XML |
---|
Dim xmlDoc Set filesys = CreateObject(“Scripting.FileSystemObject”) strQuery = “/ScanResults/File” For Each objItem in colItem WScript.Echo “Manually Deleting File: ” + fpath + fname ‘WScript.Echo objItem.nodeName & “: ” & objItem.text |