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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rsync -av /Data/ /backup/ | mail

rsync -av /Data /backup/ 2>&1  | mail

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


man mail

for more switches (subject line, etc.)
fm250Author Commented:
>> rsync -av /Data/ /backup/ | mail
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
also what does this one do.
rsync -av /Data /backup/ 2>&1  | mail

and finally this should be in a file and put in the /etc/cron.daily/
>> rsync -av /Data/ /backup/ | mail
>>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    -----

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 -s "backup" <a.tmp

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

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

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

fm250Author Commented:
>> a.tmp

append to the file or replaced it?
>> appends

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

2>&1 means "redirect the stream #2 (stderr) to stream #1(stdout)", i.e. append all error messages to your standard output.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.