Solved

Backup script

Posted on 2010-09-01
10
574 Views
Last Modified: 2012-08-13
I was going to use the code below, but I have some further requirements and I need some assistance.  I would like to get notification if the script fails and some kind of return on why it failed.  For example, a email with a exit status response.  I would also like to zip the files before sending them.

@ECHO OFF
SETLOCAL

SET _source=\\filesource

SET _dest=\\filedestination

SET _what=/COPYALL /B /SEC /MIR
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree

SET _options=/R:0 /W:0 /LOG:MyLogfile.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging

ROBOCOPY %_source% %_dest% %_what% %_options%
0
Comment
Question by:LrdKanien
  • 5
  • 3
  • 2
10 Comments
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 33580227
First,
:: is NOT proper commenting.  While it likely will work fine in the above script, there are instances where it can cause problems - BREAK THE POOR HABIT NOW and use REM.

Second, you can find a command line mailer and use that to e-mail yourself the log.  You may be able to parse the log for errors with a for command and if found, use one subject vs. another or if not found, simply not send e-mail.

As for zipping them, there are several free ZIP programs (I have used Info-Zip) that you can use.
0
 

Author Comment

by:LrdKanien
ID: 33580520
I have a mail server.  I was hoping for someone who know how to send mail using a batch file like above.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 33580568
There is no mail command in "batch" - you need a third party mailing tool.  As I said, BLAT.  (I use GBMailer, but that's hard to find).
0
 
LVL 6

Expert Comment

by:rwskas
ID: 33580807
Would you be open to having this rewritten in powershell, which does allow emailing?
0
 

Author Comment

by:LrdKanien
ID: 33580822
That's why I added other scripting languages to the post.   Was looking for someone who would recognize that.  Like a powershell script that can call that batch file and then email off afterward.  It is beyond my expertise.
0
Highfive Gives IT Their Time Back

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!

 

Author Comment

by:LrdKanien
ID: 33580828
rwskas : yes, thanks for the response.
0
 
LVL 6

Accepted Solution

by:
rwskas earned 500 total points
ID: 33580858
How about something really simple..
The below snippet calls the batch file "c:\temp\backup.bat" and then emails you the stdout (what would have been returned to the screen)
$EmailTo = "You@company.com"

$EmailFrom "BackupJOb@Company.com"

$Subject = "Backup job log"

$smtpServer = "Someservername.something.com"

$smtp = new-object Net.Mail.SmtpClient($smtpServer)



C:\temp\backup.bat >$Body

$MailMessage = new-object Net.Mail.MailMessage($emailFrom, $emailTo, $subject, $body)

$smtp.Send($MailMessage)

Open in new window

0
 

Author Comment

by:LrdKanien
ID: 33581659
leew - This is my last response to you and I'm going to call moderator attention.

rwskas - thanks for the suggested example.
0
 
LVL 6

Expert Comment

by:rwskas
ID: 33581690
I was going to write something saying something similiar about leew, was too scared of being repremanded though.  Thanks for standing up and saying something.
0
 

Author Closing Comment

by:LrdKanien
ID: 33591717
I would have liked a bit more powershell for calling the batch file that I already wrote or performing the same type of tasks via powershell.  All in all, he was very helpful and the thread was derailed by another expert.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Synchronize a new Active Directory domain with an existing Office 365 tenant
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

12 Experts available now in Live!

Get 1:1 Help Now