Source

Simple_BackUP / modules.py

Full commit
#!/usr/bin/env python

#There is additional function
#Import extentions
import smtplib
from email.mime.text import MIMEText
import os,re, datetime
from datetime import date
#Sending email
def Sendemail(fro_m,to,subject,body):
    msg = MIMEText(body)

    msg['Subject'] = subject
    msg['From'] = fro_m
    msg['To'] = to

    send = smtplib.SMTP('192.168.50.254')
    send.sendmail(fro_m, to,  msg.as_string())
    send.quit()
#Rotation files
def Rotation(arch):
#Create list name of arch
    list=[]
    for i in arch.keys():
       list.append(str(i))
#Create list of files at directory /usr/NAS/backups
    file=[]
    for root,dir,files in os.walk('/usr/NAS/backups'):
        file=files
#Create dictionary of arch wich param date:name and delete old  file if number arch more three
    for i in list:   
        delfile={}
        for j in file:
            if re.search(re.compile(i), j):
               delfile[datetime.date.fromtimestamp(os.path.getmtime('/usr/NAS/backups/'+j))]=j   
        while len(delfile)>3:
              os.remove('/usr/NAS/backups/'+delfile[min(delfile)])
              delfile.pop(min(delfile))