Source

Simple_BackUP / backup.py

FredGan 1848b37 
FredGan 5614f64 
FredGan 1848b37 




FredGan 799de46 
FredGan 5614f64 
FredGan 1848b37 
















FredGan 6acf20b 
FredGan 1848b37 

FredGan 6acf20b 


FredGan 799de46 



FredGan 6acf20b 
FredGan 799de46 
FredGan 6acf20b 


FredGan 1848b37 
FredGan 5614f64 

FredGan 1848b37 
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##########################################################################
#BACKUP FILES company "AlieParusa"                                       #
##########################################################################
import xml.parsers.expat
import tarfile
import os
import modules
from datetime import datetime

#List of path backup from XML file with name is "path.xml"
def Path():
   paths={}
   paths_list = []
   def XMLlist(name, attrs):
       paths.update(attrs)
   filepaths=open("/usr/NAS/scripts/python/path.xml", "r")
   parse=xml.parsers.expat.ParserCreate()
   parse.StartElementHandler = XMLlist
   parse.ParseFile(filepaths)
   for i in paths.keys():
       paths_list.append(paths[i])	
   return paths
#Create tar archives
def Archive(paths):
    archivepach="/usr/NAS/backups/"
    date=datetime.now().strftime('%Y'"."'%m'"."'%d')
    for i in paths:
        tar = tarfile.open(archivepach+str(i)+'_'+date+".tar", "w")
        log = open(archivepach+str(i)+'_'+date+".log", "w")
        log.write(datetime.now().strftime('%Y'"."'%m'"."'%d'" "'%H'":"'%m')+" Start task:\n")
        for root, dir, files in os.walk(str(paths[i])):
            for file in files:
                fullpath = os.path.join(root,file) 
                try:
                      tar.add(fullpath)
                except:
                      log.write(+datetime.now().strftime('%Y'"."'%m'"."'%d'" "'%H'":"'%m')+" "+"ERROR:"+fullpath+'\n')
        log.write(datetime.now().strftime('%Y'"."'%m'"."'%d'" "'%H'":"'%m')+" Finish task:\n")
        log.close()
        tar.close()
#Send email          
        modules.Sendemail(fro_m='service@redsails.ru', to='backup@redsails.ru', body='Job '+str(i)+' is done.' , subject='BackUP')
#Run processing
Archive(Path())