Solved

Backup script

Posted on 2010-09-01
10
580 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 96

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 96

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

IoT Devices - Fast, Cheap or Secure…Pick Two

The IoT market is growing at a rapid pace and manufacturers are under pressure to quickly provide new products. Can you be sure that your devices do what they're supposed to do, while still being secure?

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

623 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