Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Backup script

Posted on 2010-09-01
10
Medium Priority
?
582 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
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 2000 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

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

715 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