Solved

Backup script

Posted on 2010-09-01
10
576 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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
 

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.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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