Alternative to Safepoint - reposted

Bumping this old thread. Used a variation of the code whsbuss posted above to backup select folders to an attached USB hard drive. While the following code isn’t elegant and there are probably better ways to code it, it does appear to work for me.

The following mail.py code will use Yahoo.com email and will attach the backup.log file to the email.

#!/usr/bin/env python

# -*- coding: utf-8 -*-
import smtplib
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.MIMEBase import MIMEBase
from email import Encoders
from getpass import getpass
from smtplib import SMTP_SSL
import sys  

# edit the areas between the quotes in the line line below with your own settings. 
# Change the backup.log file location to match file to be attached to email.

login, password, server, recipients, logfile = "full.Yahoo.Email.Address.Goes.Here", "Yahoo.Password", "smtp.mail.yahoo.com", "Recipient.Email.Address", "/DataVolume/shares/system/backup.log"  

# send email

subject = sys.argv[1]
body = sys.argv[2]
msg = MIMEMultipart()
msg.attach(MIMEText(body, 'plain', 'utf-8'))
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = login
msg['To'] = recipients
part = MIMEBase('application', "octet-stream")
part.set_payload(open(logfile, "rb").read())
Encoders.encode_base64(part)
# Change file name in following line to match filename of attached file
part.add_header('Content-Disposition', 'attachment; filename="backup.log"')
msg.attach(part)
s = SMTP_SSL(server, 465, timeout=10)
s.set_debuglevel(1)
try:
    s.login(login, password)
    s.sendmail(msg['From'], recipients, msg.as_string()) 
except Exception, error:
    print "Unable to send e-mail: '%s'." % str(error)
finally:
    s.quit()

The reason for using this code was due to Safepoint being an all or nothing affair and wanting a backup process that would backup a select number of Shares and then email (with log file attached) me. The log file will show what files (if any) have been mirrored to the USB hard drive.

Can post full information/code for anyone interested.

1 Like