Thursday, October 30, 2008

Back up files that have been changed or modified seven days ago


' This script would backup all folders (including their subfolders) and files
' that are under the path specified in the objStartFolder variable.
'
' Only those files that have been modified today would be backed up.
'
' Note: if you don't want the files in .zip (or .rar) to be full path as where
' the files were original stored (using relative path in .zip file), make sure you put this script in the same
' directory of the files you want to back up. Otherwise, you would need to
' modify this script to suit your need.
'
' You can run this script in more than three ways:
' Way 1: cmd > cscript.exe script_name.vbs
' Way 2: double click on the script_name.vbs
' Way 3: run the script in scheduled tasks.

Dim MyParentPath
Dim MySubFolderFilePath

MySubFolderFilePath = ""

Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Danny\Scripts_Tools\Backup_Scripts"

' Specify the full path where the .zip will be stored, including .zip file extension and .zip file name.
ZipFileExtension = ".zip" ' can be either .zip or .rar
ZipFileName = "C:\DB_Backup_" & Year(Date()) & Month(Date()) & Day(Date()) & ZipFileExtension

dateNow = Date()

' We would like to zip the log files that have been modified from seven days ahead to the day before today (not include today)
SevenDaysAhead = shortDate( DateAdd( "d", -7, dateNow ) )

Set objFolder = objFSO.GetFolder(objStartFolder)
MyParentPath = objFolder.Path

'Wscript.Echo MyParentPath & "___"

Set colFiles = objFolder.Files
For Each objFile in colFiles
' Wscript.Echo """" & objFolder.Path & objFile.Name & """"
' Wscript.Echo """" & objFolder.Name & "\" & objFile.Name & """"
If CDate( objFile.DateLastModified ) >= CDate( SevenDaysAhead ) And CDate( objFile.DateLastModified ) < mysubfolderfilepath =" MySubFolderFilePath" wshshell =" WScript.CreateObject" wshshell =" Nothing" objfolder =" objFSO.GetFolder(Subfolder.Path)" colfiles =" objFolder.Files">= Date() Then
MySubFolderFilePath = MySubFolderFilePath & """" & Mid( objFile.ParentFolder & "\" & objFile.Name, Len(MyParentPath) + 2 ) & """" & " "
End If
Next
ShowSubFolders Subfolder
Next
End Sub

Function shortDate( theDate )
shortDate = formatdatetime( theDate, 2 )
End Function

No comments: