Last active
December 11, 2015 10:48
-
-
Save ET-CS/4589236 to your computer and use it in GitHub Desktop.
Archive-Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<job id="main"> | |
<script language="VBScript"> | |
' Copyright(c)2010 ET-CS (Etay (ET) Cohen-Solal) | |
' Set here your variables: | |
' Backup Folder | |
path = "C:\MyFolder" | |
' Destination Folder To Archive Backups. Don't Forget The Ending BackSlash '\' | |
destination = "D:\Archive\" | |
' Set Archived Filename Template By Date | |
dim time: time = NOW | |
filename = year(time) & "-" & month(time) & "-" & day(time) & ".zip" | |
' Target Folder | |
filepath = destination & filename | |
' 7-Zip Folder & Paramteres | |
exec = "C:\Progra~1\7-Zip\7z.exe " | |
param = " a -tzip " & Chr(34) & filepath & Chr(34) & " " & Chr(34) & path & Chr(34) | |
' Start Backup | |
Run exec,param | |
Set objFSO = CreateObject("Scripting.FileSystemObject") | |
If objFSO.FileExists (filepath) then | |
' Delete files.. | |
WScript.Echo "Backup Completed Succesfully." | |
Decision = msgbox("Clean Folder?",vbyesno,"Backup Comleted") | |
if Decision=vbYes then | |
RecursiveEmptyFolder(path) | |
end if | |
wscript.quit | |
else | |
WScript.Echo "Backup Failed!" | |
wscript.quit | |
end if | |
Sub EmptyFolder(ByVal sDirectoryPath) | |
on error resume next | |
Dim oFSO | |
Dim oFolder | |
Dim oFileCollection | |
Dim oFile | |
Set oFSO = CreateObject("Scripting.FileSystemObject") | |
set oFolder = oFSO.GetFolder(sDirectoryPath) | |
set oFileCollection = oFolder.Files | |
'If database backup files are older than 1 days, delete them. | |
For each oFile in oFileCollection | |
'If oFile.DateLastModified < (Date() - iDaysOld) Then | |
oFile.Delete(True) | |
'End If | |
Next | |
'Clean up | |
Set oFSO = Nothing | |
Set oFolder = Nothing | |
Set oFileCollection = Nothing | |
Set oFile = Nothing | |
End Sub | |
Sub RecursiveEmptyFolder(ByVal sDirectoryPath) | |
Set oFSO = CreateObject("Scripting.FileSystemObject") | |
ProcessSubFolders oFSO.GetFolder(sDirectoryPath), iCount | |
WScript.Echo "Files deleted: " & iCount | |
End Sub | |
Sub ProcessSubFolders(oFolder, iCount) | |
Set cFiles = oFolder.Files | |
For Each oFile In cFiles | |
oFile.Delete | |
iCount = iCount + 1 | |
Next | |
For Each oSubFolder In oFolder.SubFolders | |
ProcessSubFolders oSubFolder, iCount | |
oSubFolder.Delete | |
Next | |
End Sub | |
Sub Run(ByVal sFile, ByVal sParam) | |
Dim shell | |
Set shell = CreateObject("WScript.Shell") | |
Batch = sFile & sParam | |
shell.Run Batch, 1, true | |
Set shell = Nothing | |
End Sub | |
</script> | |
</job> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment