Backup por E-mail com Shell Script

1 – Instale o ssmtp e o mutt

apt-get install ssmtp mutt

2 – Configure o ssmtp

vi /etc/ssmtp/ssmtp.conf

hostname=localhost
rewriteDomain=<strong>gmail.com</strong>
AuthUser=<strong>meuemail@gmail.com</strong>
AuthPass=<strong>minhasenha</strong>
AuthMetod=plain
FromLineOverride=NO
Mailhub=<strong>smtp.gmail.com:465</strong>
UseTLS=YES

3 – Crie o arquivo que conterá o corpo de email:

echo "a b c" > corpo_email

4 – Enviando email com anexo utilizando o mutt

mutt -s "Assunto" -i corpo_email -a /etc/iptables.regras -c lancelot@gmail.com < /dev/null

Exemplo de Script

#!/bin/bash
# Envia anexo para conta no gmail

MAILTO=lancelot@gmail.com
SUBJECT='[ BACKUP SERVIDOR ]'
ATTACH=/tmp/home_user_dev_srv.tar.bz2

# Apaga arquivo gerado pelo mutt antes de gerar backup 
rm -f $HOME/sent

# Gera backup
tar -cjvf $ATTACH /home/user

# ENVIA E-MAIL
mutt -s "$SUBJECT" -a $ATTACH -c $MAILTO < /dev/null

# Apaga arquivo gerado pelo mutt depois de enviar e-mail 
rm -f $HOME/sent
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s