Robocopy Backup Script

From INIwiki
(Redirected from Windows/WSH)
Jump to: navigation, search

Digg this!

<meta name="keywords" content="windows, robocopy, file baclup"></meta> <meta name="description" content="Windows robocopy backup script."></meta>

[edit] Robocopy Backup Script

[edit] Description:

Script using Robocopy to backup directories or disks The function of this script is adding excludelists functionality to the tool robocopy.exe simply modify the first 5 working lines of the script and make two text files with the directories and files to exclude. Excludedirs.txt should contain paths to directories that should be excluded from backup. Excludefiles.txt should contain filenames (wildcards should work to) that should be excluded from backup. For both files you should enter one file/directory on each line of the textfile.

[edit] Script:

'===
' robocopy.vbs
' Script using Robocopy to backup directories or disks
' The function of this script is adding excludelists 
' functionality to the tool robocopy.exe
' simply modify the first 5 working lines of the script
' and make two text files with the directories and files
' to exclude. Excludedirs.txt should contain paths to 
' directories that should be excluded from backup. 
' Excludefiles.txt should contain filenames (wildcards
' should work to) that should be excluded from backup. 
' For both files you should enter one file/directory 
' on each line of the textfile.
' Build by Frans Erich
'===
EXCLUDEDIRS = "D:\excludedirs.txt"
EXCLUDEFILES = "D:\excludefiles.txt"
ROBOCOPYLOCATION = "D:\robocopy.exe"
SOURCELOCATION = "D:\test1"
TARGETLOCATION = "D:\test2"
Const FOR_READING = 1
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(EXCLUDEDIRS, FOR_READING)
strDirExclude = objFile.ReadAll
objFile.Close
Set objFile = objFSO.OpenTextFile(EXCLUDEFILES, FOR_READING)
strFileExclude = objFile.ReadAll
objFile.Close
arrDirExclude = Split(strDirExclude, vbCrLf)
arrFileExclude = Split(strFileExclude, vbCrLf)
For Each dir In arrDirExclude
dirs = dirs + " /xd " + chr(34) + dir + chr(34)
Next
For Each bestand In arrFileExclude
bestanden = bestanden + " /xf " + chr(34) + bestand + chr(34)
Next
mycommand = ROBOCOPYLOCATION & chr(32) & SOURCELOCATION & chr(32)&TARGETLOCATION & " /MIR /r:0 /w:0 " & dirs & bestanden WshShell.Run(mycommand)

Source: Author: Frans Erich

Digg this!

Personal tools