FredGan committed c50c427

Rotation arch files

Comments (0)

Files changed (2)

     logging.basicConfig(filename=archivepach+'logs'+'_'+date+'.log',format='%(asctime)s %(message)s',level=logging.DEBUG)
+    body=''
     for i in paths:'Start task: '+str(i))
         tar ='_'+date+".tar", "w")
                       logging.warning("Error: "+fullpath)'Finish task: '+str(i))
+        body=body+'Job '+str(i)+' is done.\n'
 #Send email          
-        modules.Sendemail(fro_m='', to='', body='Job '+str(i)+' is done.' , subject='BackUP')
+    modules.Sendemail(fro_m='', to='', body=body , subject='BackUP')
 #Run processing
 #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)
     send = smtplib.SMTP('')
     send.sendmail(fro_m, to,  msg.as_string())
+#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, j):
+               delfile['/usr/NAS/backups/'+j))]=j   
+        while len(delfile)>3:
+              os.remove('/usr/NAS/backups/'+delfile[min(delfile)])
+              delfile.pop(min(delfile))