Solved

Copy Folder to remote server with email confirmation

Posted on 2007-11-15
7
787 Views
Last Modified: 2010-08-05
Hello Experts,

I have a simple script that runs nightly to copy file backups from a local server to a remote server. It works well, but i would like to add some enhanced functionality. I'd like to add the script to include a start time and endtime logfile to be emailed to me upon completion.  

I am using objFSO.CopyFolder for the copy function, and I have tested simple CDO messages (they work in my environment) but I don't know how to package it all together into one script.

Any help with this would be greatly appreciated!
0
Comment
Question by:Phosphor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 18

Expert Comment

by:carl_legere
ID: 20291458
my backup scripts are all using febootimail paid version to send me the results of the backup script.

date /t > c:\backupscript\output.txt
time /t >> c:\backupscript\output.txt
backup script output >> c:\backupscript\output.txt
febootimail -FROM administrator@domain.com -TO backup@domain.com -MSG "See attached backup log" -SUBJ "Backup Report" -ATTACH output.txt
0
 
LVL 1

Author Comment

by:Phosphor
ID: 20291659
I don't have any problems using CDO for mail. These are not typical backup files, they are encrypted and compressed zip files and I can schedule those from WinZipPro along with comprehensive log files and an email status report.

However, what is sort of important to me is to be able to get a handle on how long these transfers take because they are quite large and it will tell me if my WAN link is stable (consistant speed) and If I need to break it up into smaller files, etc. I tried using simple compress with WSH but the file size was too big (well over 3Gb) and zipping them gets me down to aroung 800MB. It seems to take about 1.5 - 2 hrs to upload the files, but I want hard numbers to be able to chart the efficiency.
0
 
LVL 18

Accepted Solution

by:
carl_legere earned 375 total points
ID: 20294869
write a time date stamp to a homemade log file before the transfer, then concat a new time date stamp after, use cdo to send yourself this as email telling you the length of time for the transfer
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Phosphor
ID: 20298287
What I don't understand is how does the script know when the file transfer is complete?  Remember that it's gonna take ~ 2hrs. to complete.
Does it happen automatically while the script runs or do I need to write/loop something to say "wait until file upload completes" maybe linked to a progress bar or something, and then it appends the textfile.
0
 
LVL 1

Author Comment

by:Phosphor
ID: 20299239
Here is what I have in code so far, it works so far, but I still want to improve upon it by populating the subject line with completed/not completed status output. In the body of the email I'd like to include the timestamp converted to minutes.
'Step1 Start a text file
strFile = "H:\TestDest\remotecopylog.txt"
Set objFSO = CreateObject ("Scripting.FileSystemObject")
If Not objFSO.FileExists (strFile) Then
OverwriteFile
Else
 
End If
 
'Step2 Write Start
 
Const FOR_APPENDING = 8
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile ("H:\TestDest\remotecopylog.txt",  FOR_APPENDING, True)
objFile.WriteLine "START Remote copy Transfer Time START "  & Now
objFile.WriteBlankLines(1)
objFile.WriteLine "End"
objFile.WriteBlankLines(2)
objFile.Close
 
WScript.Sleep 100
 
'Step3 Start CopyFolder w- progress
Const FOF_CREATEPROGRESSDLG = &H0&
 
strTargetFolder = "H:\TestFolder-D" 
 
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strTargetFolder) 
 
objFolder.CopyHere "H:\TestFolder-S", FOF_CREATEPROGRESSDLG
 
'Step4 WriteEnd
'Const FOR_APPENDING = 8 'Pulled error message L:36 CH:7 "Name Redefined"
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile ("H:\TestDest\remotecopylog.txt",  FOR_APPENDING, True)
objFile.WriteLine "Remote copy Transfer Time END "  & Now
objFile.WriteBlankLines(1)
objFile.WriteLine "End"
objFile.WriteBlankLines(2)
objFile.Close
 
WScript.Sleep 100
 
'Start Mail Message
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Copy backups to remote server status"
objMessage.Sender = "administrator@box.com"
objMessage.From = "administrator@box.com"
objMessage.To = "5050@box.com"
objMessage.TextBody = "The following files were uploaded successfully to [Servername] in XXX minutes to [path]"
objMessage.AddAttachment "H:\TestDest\remotecopylog.txt"
 
'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
 
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server"
 
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
 
objMessage.Send

Open in new window

0
 
LVL 1

Author Comment

by:Phosphor
ID: 20319829
A problem arose when the copy procedure ran and the folder already exists.
Is there a way to keep the progress bar and still set the file to overwrite?

I Can do this:
Const FOF_CREATEPROGRESSDLG = &H0&
Const OverWriteFiles = True
strTargetFolder = "\\server\access\"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strTargetFolder)
objFolder.CopyHere "C:\Source", FOF_CREATEPROGRESSDLG

And if the folder exists, it prompts to overwrite. I have tried to use Const = True in the last line but throws an error (too many arguments) If I comment out FOF_CREATEPROGRESSDLG item it overwrites, but I get no Progress indicator.

If I use the following:

Set objFSO = CreateObject("Scripting.fileSystemObject")
Const FOF_CREATEPROGRESSDLG = &H0&
Const OverWriteFiles = True
sFolder = "C:/Source"
dFolder = "\\server\access\"
Set objFSO = CreateObject("Scripting.fileSystemObject")
objFSO.CopyFolder sFolder, dFolder, OverWriteFiles
FOF_CREATEPROGRESSDLG

It overwrites with no progressbar. Is there a way end the progreesbar?

 -or- how can I roll both functions into the procedure?
0
 
LVL 1

Author Closing Comment

by:Phosphor
ID: 31409390
Thanks for the idea.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question