Solved

Backup script

Posted on 2010-09-01
10
578 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 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