Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 794
  • Last Modified:

Copy Folder to remote server with email confirmation

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
Phosphor
Asked:
Phosphor
  • 5
  • 2
1 Solution
 
carl_legereCommented:
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
 
PhosphorAuthor Commented:
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
 
carl_legereCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
PhosphorAuthor Commented:
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
 
PhosphorAuthor Commented:
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
 
PhosphorAuthor Commented:
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
 
PhosphorAuthor Commented:
Thanks for the idea.
0

Featured Post

Independent Software Vendors: 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!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now