Solved

Copy Folder to remote server with email confirmation

Posted on 2007-11-15
7
780 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now