Link to home
Start Free TrialLog in
Avatar of fm250
fm250Flag for United States of America

asked on

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
Avatar of m1tk4
m1tk4
Flag of United States of America image

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.)
Avatar of fm250

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of m1tk4
m1tk4
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fm250

ASKER

will
>> a.tmp

append to the file or replaced it?
>> appends

> replaces and starts anew.
Avatar of fm250

ASKER

What does 2>&1 means?  in  rsync -av /Data /backup/ 2>&1 >>a.tmp;
also how do I add ther errors?

Thanks!
2>&1 means "redirect the stream #2 (stderr) to stream #1(stdout)", i.e. append all error messages to your standard output.