DBAsupport.com Forums - Powered by vBulletin
Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: Script to housekeeping Archived logfiles on Win2K

  1. #21
    Join Date
    Apr 2001
    Posts
    110
    Dear All,

    Thanks for all the solutions.

    I finally found a VB script to do what I want.
    Just need to change the sDay and sFolder parameter to suit your needs.
    E.g. If your archived files are located at M:\Test\archive, then the sFolder parameter should be M:\Test.
    That's how this VB script works.

    Just use Windows Task scheduler to make it run at the time you need. (I guess everyone knows that!)

    Cheers
    Peng Soon

    VB Code:

    Option Explicit
    'On Error Resume Next

    'Global variables
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Dim objFSO, objFolder, objSubFolder, objFile, sLog, sFolder, LogFile, sDay, sOut
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    'User Define variable for target folder and log file
    sDay = "7"
    sFolder = "M:\Test"
    sLog = objFSO.GetAbsolutePathName(".") & "\FileMgmt.txt"
    Set LogFile = objFSO.OpenTextFile(sLog, ForWriting, True)

    'Main Program
    ShowSubFolders objFSO.GetFolder(sFolder)

    'Clean Up
    LogFile.Close
    Set objFSO=Nothing
    Set objFile=Nothing
    MsgBox ("Finish")
    WScript.Quit(0)

    'Sub Routine
    Sub ShowSubFolders(Folder)
    On Error Resume Next

    For Each objSubFolder in Folder.SubFolders
    'Wscript.Echo objSubFolder.Path
    If (objSubFolder.Size > 0) Then
    CheckFiles objSubFolder
    ShowSubFolders objSubFolder
    Else
    'Wscript.Echo "Folder Deleted:" & chr(9) & objSubfolder.Name & chr(9) & objSubfolder.DateCreated
    sOut = objSubfolder.Name & chr(9) & objSubfolder.DateCreated & chr(13) & chr(10)
    'LogFile.Write "Folder Will be Deleted:" & chr(9) & sOut
    objFSO.DeleteFolder(objSubFolder), True
    If (Err.Number <> 0) Then
    LogFile.Write "Folder NOT Deleted:" & chr(9) & sOut
    Else
    LogFile.Write "Folder Deleted:" & chr(9) & sOut
    End If
    End If
    'ShowSubFolders objSubFolder
    Next
    End Sub

    Sub CheckFiles(Folder)
    Set objFile = Folder.Files
    For Each objFile In objFile
    'If DateValue(Date) > DateValue(objFile.DateLastAccessed + sDay) Then
    'If DateValue(Date) > DateValue(objFile.DateLastModified + sDay) Then
    If DateValue(Date) > DateValue(objFile.DateCreated + sDay) Then
    'Wscript.Echo "File Deleted:" & chr(9) & objFile.Name & chr(9) & objFile.DateCreated
    sOut = objFile.Name & chr(9) & objFile.DateCreated & chr(13) & chr(10)
    'LogFile.Write "File will be Deleted:" & chr(9) & sOut
    objFSO.DeleteFile(objFile), True
    If (Err.Number <> 0) Then
    LogFile.Write "File NOT Deleted:" & chr(9) & sOut
    Else
    LogFile.Write "File Deleted:" & chr(9) & sOut
    End If
    End If
    Next
    End Sub
    What's next after 10g?

  2. #22
    Join Date
    Aug 2002
    Location
    Atlanta
    Posts
    1,187
    Originally posted by oracbase
    Dear All,

    Thanks for all the solutions.

    I finally found a VB script to do what I want.
    Just need to change the sDay and sFolder parameter to suit your needs.
    E.g. If your archived files are located at M:\Test\archive, then the sFolder parameter should be M:\Test.
    That's how this VB script works.

    Just use Windows Task scheduler to make it run at the time you need. (I guess everyone knows that!)

    Cheers
    Peng Soon

    VB Code:

    Option Explicit
    'On Error Resume Next

    'Global variables
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Dim objFSO, objFolder, objSubFolder, objFile, sLog, sFolder, LogFile, sDay, sOut
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    'User Define variable for target folder and log file
    sDay = "7"
    sFolder = "M:\Test"
    sLog = objFSO.GetAbsolutePathName(".") & "\FileMgmt.txt"
    Set LogFile = objFSO.OpenTextFile(sLog, ForWriting, True)

    'Main Program
    ShowSubFolders objFSO.GetFolder(sFolder)

    'Clean Up
    LogFile.Close
    Set objFSO=Nothing
    Set objFile=Nothing
    MsgBox ("Finish")
    WScript.Quit(0)

    'Sub Routine
    Sub ShowSubFolders(Folder)
    On Error Resume Next

    For Each objSubFolder in Folder.SubFolders
    'Wscript.Echo objSubFolder.Path
    If (objSubFolder.Size > 0) Then
    CheckFiles objSubFolder
    ShowSubFolders objSubFolder
    Else
    'Wscript.Echo "Folder Deleted:" & chr(9) & objSubfolder.Name & chr(9) & objSubfolder.DateCreated
    sOut = objSubfolder.Name & chr(9) & objSubfolder.DateCreated & chr(13) & chr(10)
    'LogFile.Write "Folder Will be Deleted:" & chr(9) & sOut
    objFSO.DeleteFolder(objSubFolder), True
    If (Err.Number <> 0) Then
    LogFile.Write "Folder NOT Deleted:" & chr(9) & sOut
    Else
    LogFile.Write "Folder Deleted:" & chr(9) & sOut
    End If
    End If
    'ShowSubFolders objSubFolder
    Next
    End Sub

    Sub CheckFiles(Folder)
    Set objFile = Folder.Files
    For Each objFile In objFile
    'If DateValue(Date) > DateValue(objFile.DateLastAccessed + sDay) Then
    'If DateValue(Date) > DateValue(objFile.DateLastModified + sDay) Then
    If DateValue(Date) > DateValue(objFile.DateCreated + sDay) Then
    'Wscript.Echo "File Deleted:" & chr(9) & objFile.Name & chr(9) & objFile.DateCreated
    sOut = objFile.Name & chr(9) & objFile.DateCreated & chr(13) & chr(10)
    'LogFile.Write "File will be Deleted:" & chr(9) & sOut
    objFSO.DeleteFile(objFile), True
    If (Err.Number <> 0) Then
    LogFile.Write "File NOT Deleted:" & chr(9) & sOut
    Else
    LogFile.Write "File Deleted:" & chr(9) & sOut
    End If
    End If
    Next
    End Sub

    dude are you kidding me? you're gonna split the atom here when rman already does this for you with like may less code
    I'm stmontgo and I approve of this message

  3. #23
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Originally posted by stmontgo
    dude are you kidding me? you're gonna split the atom here when rman already does this for you with like may less code
    Why do something the easy way when you can write VB code???
    Jeff Hunter

  4. #24
    Join Date
    Aug 2002
    Location
    Atlanta
    Posts
    1,187
    Originally posted by marist89
    Why do something the easy way when you can write VB code???
    my bad, carry on, perhaps C+ would be more of a challenge
    I'm stmontgo and I approve of this message

  5. #25
    Join Date
    Apr 2001
    Posts
    110
    Dear All,

    Sorry about the long VB script.

    I know the benefits of RMAN.
    Some of our databases are using RMAN backup, but not all our database can use RMAN backup.

    There is always constraints when implementing certain things.

    Thanks for all your input.

    Why I post the VB script?
    Reason is I am used to using UNIX shell scripts to perform the same tasks, but fine it such a chore on Windows to find a similar thing to do the same job.

    Cheers
    Oracbase
    What's next after 10g?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width