You can use the script (code in the 'Script' paragraph) to spike duplicated images from database (collected by query explained in Query to find duplicate images.)
Before running the script, set up the INI file, specifying the name of your GN4 server, the name of the GN4 database, the name of the table where duplicate ids are stored, credentials to connect (user and password), and some other data.
Then you can run the script with:
cscript GN4Cleaner.vbs
After the deleting you can force a purge manually with srv4.
[Servername] SERVER [Databasename] GN4 [Tablename] _DupImgTable [User] sa [Password] password [NObjSpike] 100 [BIN_PATH] C:\TERA\GN4\BIN |
Dim Servername, Databasename, Tablename, User, Password, NObjSpike, Bin_Path Dim Partenza, Arrivo Dim ScriptPath, ScriptLog Dim Ids(), Rcount
Partenza = Time
' **** Script setting default ****
set args = WScript.Arguments
Servername = "OMEGA" Databasename = "TarkDemo" Tablename = "_DupImgTable" User = "sa" Password = "blu0frog" NObjSpike = 100 Bin_Path = "C:\TERA\TARK4\BIN"
ScriptPath = left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-14)
' ****Create Full Script Log ****
ScriptLog = ScriptPath + "ScriptFull.log" Set ScrFSO = CreateObject("Scripting.FileSystemObject") ScrFSO.CreateTextFile(ScriptLog) Set ScrFile = ScrFSO.GetFile (ScriptLog) Set ScrTextStream = ScrFile.OpenAsTextStream(2) ScrTextStream.Writeline "--------------------------------------------------------------------------------" ScrTextStream.Writeline "--------------------------------FULL SCRIPT LOG---------------------------------" ScrTextStream.Writeline "--------------------------------------------------------------------------------"
Select case args.Count case 0 Inifile = ScriptPath + "GN4Cleaner.ini" WScript.Echo "Using default ini... " + Inifile WScript.Echo ScrTextStream.Writeline "Using default ini... " + Inifile ScrTextStream.Writeline case 1 Inifile = args.Item(0) WScript.Echo "Using custom ini... " + Inifile WScript.Echo ScrTextStream.Writeline "Using custom ini... " + Inifile ScrTextStream.Writeline case else WScript.Echo "Usage: GN4Cleaner.vbs [Ini filename]" WScript.Echo ScrTextStream.Writeline "Usage: GN4Cleaner.vbs [Ini filename]" ScrTextStream.Writeline WScript.Quit 1 end select
WScript.sleep 1000
Dim Conn Dim rs Dim Query
TimeO = 200
' ****All sequential routines ****
Readini DisplaySetting OpenDBConnection Counting CollectingId CloseDBConnection
' **** Script end ****
Arrivo = Time WScript.Echo "GN4 duplicated objects cleanup started on " & Partenza & " terminated on " & Arrivo ScrTextStream.Writeline "GN4 duplicated objects cleanup started on " & Partenza & " terminated on " & Arrivo ScrTextStream.Writeline ScrTextStream.Writeline "--------------------------------------------------------------------------------" ScrTextStream.Writeline "---------------------------------END SCRIPT LOG---------------------------------" ScrTextStream.Writeline "--------------------------------------------------------------------------------" ScrTextStream.close WScript.Quit 1
' **************************** ' **** ALL THE SUBROUTINE **** ' ****************************
Sub Readini ' **** Reading TarkToTark4.ini file **** WScript.Echo "Reading ini file..." ScrTextStream.Writeline "Reading ini file..." WScript.sleep 1000 Set fso = CreateObject("Scripting.FileSystemObject") Set dbFile = fso.GetFile (Inifile) Set dbTextStream = dbFile.OpenAsTextStream(1) Corrupted = false Riga = dbTextStream.ReadLine if Riga = "[Servername]" then Servername = dbTextStream.ReadLine else Corrupted = true end if Riga = dbTextStream.ReadLine if Riga = "[Databasename]" then Databasename = dbTextStream.ReadLine else Corrupted = true end if Riga = dbTextStream.ReadLine if Riga = "[Tablename]" then Tablename = dbTextStream.ReadLine else Corrupted = true end if Riga = dbTextStream.ReadLine if Riga = "[User]" then User = dbTextStream.ReadLine else Corrupted = true end if Riga = dbTextStream.ReadLine if Riga = "[Password]" then Password = dbTextStream.ReadLine else Corrupted = true end if Riga = dbTextStream.ReadLine if Riga = "[NObjSpike]" then NObjSpike = cint(dbTextStream.ReadLine) else Corrupted = true end if Riga = dbTextStream.ReadLine if Riga = "[BIN_PATH]" then Bin_Path = dbTextStream.ReadLine else Corrupted = true end if dbTextStream.close if Corrupted = true then WScript.Echo "Ini file corrupted" WScript.Echo "The ini file must have this structure" WScript.Echo WScript.Echo "[Servername]" WScript.Echo "[Databasename]" WScript.Echo "[Tablename]" WScript.Echo "[User]" WScript.Echo "[Password]" WScript.Echo "[NObjSpike]" WScript.Echo "[BIN_PATH]" ScrTextStream.Writeline "Ini file corrupted" ScrTextStream.Writeline "The ini file must have this structure" ScrTextStream.Writeline ScrTextStream.Writeline "[Servername]" ScrTextStream.Writeline "[Databasename]" ScrTextStream.Writeline "[Tablename]" ScrTextStream.Writeline "[User]" ScrTextStream.Writeline "[Password]" ScrTextStream.Writeline "[NObjSpike]" ScrTextStream.Writeline "[BIN_PATH]" WScript.Quit 1 else WScript.Echo "Ini file correct" ScrTextStream.Writeline "Ini file correct" WScript.Echo ScrTextStream.Writeline WScript.sleep 1000 end if End sub
Sub DisplaySetting ' **** displaing script setting **** WScript.Echo "-------------------------------------------" WScript.Echo " Script Setting " WScript.Echo "-------------------------------------------" WScript.Echo "Server Name: " + Servername WScript.Echo "DataBase Name: " + Databasename WScript.Echo "Table Name for object to spike: " + Tablename WScript.Echo "Sql User: " + User WScript.Echo "Sql Password: " + Password WScript.Echo "Object to spike in cicle: " + cstr(NObjSpike) WScript.Echo "Bin Path: " + Bin_Path WScript.Echo WScript.Echo WScript.Echo WScript.Echo "Check if the parameters are correct" WScript.Echo "Use CTRL+C if you want to break it" ScrTextStream.Writeline "-------------------------------------------" ScrTextStream.Writeline " Script Setting " ScrTextStream.Writeline "-------------------------------------------" ScrTextStream.Writeline "Server Name: " + Servername ScrTextStream.Writeline "DataBase Name: " + Databasename ScrTextStream.Writeline "Table Name for object to spike: " + Tablename ScrTextStream.Writeline "Sql User: " + User ScrTextStream.Writeline "Sql Password: " + Password ScrTextStream.Writeline "Object to spike in cicle: " + cstr(NObjSpike) ScrTextStream.Writeline "Bin Path: " + Bin_Path ScrTextStream.Writeline ScrTextStream.Writeline ScrTextStream.Writeline ScrTextStream.Writeline "Check if the parameters are correct" ScrTextStream.Writeline "Use CTRL+C if you want to break it" strMessage = "Press the ENTER key to continue. " Wscript.StdOut.Write strMessage Do While Not WScript.StdIn.AtEndOfLine Input = WScript.StdIn.Read(1) Loop WScript.Echo ScrTextStream.Writeline End sub
Sub OpenDBConnection ' **** create database connection **** Set Conn = CreateObject("ADODB.Connection") Conn.Provider = "sqloledb" Conn.Properties("Data Source").Value = Servername Conn.Properties("Initial Catalog").Value = Databasename Conn.Properties("User ID").Value = User Conn.Properties("Password").Value = Password Conn.ConnectionTimeout = TimeO Conn.CommandTimeout = TimeO Conn.open End sub
Sub Counting ' **** Counting Objs records **** WScript.Echo "Counting objects to spike in " + Tablename + " table..." ScrTextStream.Writeline "Counting objects to spike in " + Tablename + " table..." Query = "SELECT COUNT(id) AS TotalCount FROM " + Tablename ScrTextStream.Writeline Query set rs = conn.execute(Query) TotObjs = rs(0) WScript.Echo "Founds n° " + cstr(TotObjs) + " objects" WScript.Echo ScrTextStream.Writeline "Founds n° " + cstr(TotObjs) + " objects" ScrTextStream.Writeline End sub
Sub CollectingId ReDim Ids(NObjSpike) Query = "SELECT id FROM " + Tablename WScript.Echo "Executing query..." WScript.Echo Query ScrTextStream.Writeline "Executing query..." ScrTextStream.Writeline Query Set rs = CreateObject("ADODB.Recordset") rs.Open Query, Conn, 0, 1, 1 WScript.Echo "Query executed!" ScrTextStream.Writeline "Query executed!" Do while not(rs.EOF) Rcount = Rcount + 1 Ids(Rcount) = rs.fields.item(0).value rs.MoveNext if Rcount = NObjSpike or rs.EOF = true then Srv4Spike end if Loop End sub
Sub CloseDBConnection ' **** Close connection **** conn.close set rs = nothing set conn = nothing End sub
Sub Srv4Spike Set oShell = WScript.CreateObject("WSCript.shell") WScript.sleep 2000 Idlist = "" For I = 1 to Rcount if I < Rcount then Idlist = Idlist + cstr(Ids(I)) + "," else Idlist = Idlist + cstr(Ids(I)) end if Next WScript.Echo WScript.Echo "Execute srv4 deleting on " + cstr(I-1) + " objcets..." WScript.Echo "----------------------------------------------------" ScrTextStream.Writeline ScrTextStream.Writeline "Execute srv4 deleting on " + cstr(I) + " objcets..." ScrTextStream.Writeline "--------------------------------------------------" srv4cmd = Bin_Path + "\srv4.exe spike -ids " + Idlist WScript.Echo srv4cmd ScrTextStream.Writeline srv4cmd oShell.run srv4cmd, 1, true Rcount = 0 ReDim Ids(NObjSpike) End sub
|