Solved

Copy Folder to remote server with email confirmation

Posted on 2007-11-15
7
782 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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