So you need a quick method to grabing folders from a UNC path and place a copy of them on a removable drive. I had a customer who wanted to do the old USB drive swap for off site backup storage. I tried to explain that now with the advent of the cloud we could move the files off site without any user intervention but they really wanted to do it manually.
So here is a Automated script to help with a manual process.
Here is the basic beak down of the script.
In the first part of the script we set the email server to relay mail to, our domain name and the email addresses we want to send reports to.
‘ Company Internet Domain Name
ODomain = “mydoamin.com”
‘ Set the SMTP server IP
oMyIP = “192.168.1.5”
‘ Where do you want the message to be delivered
oTo = “myemail@mydomain.com;another@email.com“
This next part sets up the local directory we will be copying to, The script during execution will delete all things off the drive and then rebuilds the directory structure you want so we have to tell it the directory we want added back after the delete.
‘### Check folders exist and prep for copy
Dim oName, ODomain, oMyIP, oTo, newfolder, newfolderpath
Set FSO =CreateObject(“scripting.FileSystemObject”)‘###Change my folder path ######################
If FSO.FolderExists(“F:\Backup\”) Then
FSO.DeleteFolder “F:\Backup”
wscript.sleep 90000
End If‘##### Change My folder path#########
newfolderpath = “F:\Backup”
If Not FSO.FolderExists(newfolderpath) Then
Set newfolder = FSO.CreateFolder(newfolderpath)
wscript.sleep 5000
End If
Now we need to start the actual copy and get some files on our removable disk. You will need to edit the “newfolderpath” so it reflects where you want the files copied to. You will need to edit the FSO.CopyFilder so that it resembles your UNC path. You can copy the em=ntire code block and repeat over and over again for multiple UNC paths or folders.
‘###Grab files and place them in new folder (We must create that new folder now)
‘### Change my new folder path ###################
newfolderpath = “F:\Backup\MyNewfOLDER”If Not FSO.FolderExists(newfolderpath) Then
Set newfolder = FSO.CreateFolder(newfolderpath)
End IfFSO.CopyFolder “\\MyIP Address\MyShare\MyFolder”, “F:\Backup\mYNewFolder” ,True
wscript.sleep 5000‘### You can copy the top several lines starting with the new folder creation and repeat as many times as needed. This will allow for mulitple locations and folder
Next we write an event log in windows reporting that we completed the copies.
Set WshShell = WScript.CreateObject(“WScript.Shell”)
strCommand = “eventcreate /T Warning /ID 99999 /L SYSTEM /D ” & _
Chr(34) & “The Script has completed the scheduled backup copy to the offsite drive (F:)” & Chr(34)
WshShell.Run strcommand
Then we send off a email to the users we set in the above script area.
‘ Get the computer name
Set WshNetwork = CreateObject(“WScript.Network”)
oName = WshNetwork.ComputerName
‘ Set the visual basic constants as they do not exist within VBScript.
‘ Do not set your smtp server information here.
Const cdoSendUsingMethod = “http://schemas.microsoft.com/cdo/configuration/sendusing“, _
cdoSendUsingPort = 2, _
cdoSMTPServer = “http://schemas.microsoft.com/cdo/configuration/smtpserver”‘ Create the CDO connections.
Dim iMsg, iConf, Flds
Set iMsg = CreateObject(“CDO.Message”)
Set iConf = CreateObject(“CDO.Configuration”)
Set Flds = iConf.Fields‘ SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort‘ Set the SMTP server address here.
.Item(cdoSMTPServer) = oMyIP
.Update
End With‘ Set the message properties.
With iMsg
Set .Configuration = iConf
.To = oTo
.From = oName & “@” & oDomain
.Subject = “Backup Copy to Offsite Drive Started”
.TextBody = “The NTVI Server Backup copying is now taking place. The drive should be ready to remove offsite.”
End With‘ An attachment can be included.
‘iMsg.AddAttachment Attachment‘Send the message.
iMsg.Send
Thats it, You can download a zipped copy of the entire script using the above link.
I hope this helps you, Enjoy..
Cubert
Great items from you, man. I’ve take into account your stuff prior to and you’re just too fantastic.
I really like what you have obtained right here, certainly like what you’re stating and the way in which
during which you are saying it. You are making it enjoyable and you continue to take care of to keep it sensible.
I can’t wait to read much more from you. That is actually a wonderful web
site.
What is the website that means it is easy to understand podcasts and blog sites? I don’t get an iPod, does that make any difference? . edkkfkgkcbed