backup script with email notification

I want to have a backup script that would backup using the rsync and run everyday. when the script is done I would like it to send me a notification email with result. for example if I put

rsync -av /Data/ /backup/

I would like to see the result of that as if I am running it from the shell. Please provide the script if possible. I have latest kernal. Thank you
LVL 10
fm250Asked:
Who is Participating?
 
m1tk4Commented:
>>So
>> rsync -av /Data/ /backup/ | mail myemailaddress@somwehere.com
>>will this one wait for all of output of the command
>>rsync -av /Data/ /backup/
>>and then send it to email.

Yes.

>>what if you want more nice email for example
>>subject: backup
>>body: result of the backup sync    -----

You do it this way:

echo "result of the backup sync" > a.tmp; echo " " >> a.tmp; echo "----" >> a.tmp; rsync -av /Data /backup/ 2>&1 >>a.tmp; mail myemailaddress@somwehre.com -s "backup" <a.tmp

>>and finally this should be in a file whatevername.sh and put in the /etc/cron.daily/
>>correct?

Yes, pretty much. Don't forget a shebang (#!/bin/bash) in the first line and to make the file executable (chmod a+x whatevername.sh).

Also, if you are executing it from crond, you have to use full versions of some commands as path is not always available, i.e.

/bin/mail instead of mail and /usr/bin/rsync instead of rsync.


0
 
m1tk4Commented:
rsync -av /Data/ /backup/ | mail myemailaddress@somwehere.com

rsync -av /Data /backup/ 2>&1  | mail myemailaddress@somwehere.com

if you want to send the error messages (stderr) too.

See

man mail

for more switches (subject line, etc.)
0
 
fm250Author Commented:
So
>> rsync -av /Data/ /backup/ | mail myemailaddress@somwehere.com
will this one wait for all of output of the command
rsync -av /Data/ /backup/
and then send it to email.  what if you want more nice email for example
subject: backup
body: result of the backup sync    -----

result here
--end---
also what does this one do.
rsync -av /Data /backup/ 2>&1  | mail myemailaddress@somwehere.com

and finally this should be in a file whatevername.sh and put in the /etc/cron.daily/
correct?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
fm250Author Commented:
will
>> a.tmp

append to the file or replaced it?
0
 
m1tk4Commented:
>> appends

> replaces and starts anew.
0
 
fm250Author Commented:
What does 2>&1 means?  in  rsync -av /Data /backup/ 2>&1 >>a.tmp;
also how do I add ther errors?

Thanks!
0
 
m1tk4Commented:
2>&1 means "redirect the stream #2 (stderr) to stream #1(stdout)", i.e. append all error messages to your standard output.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.