Source

Simple_BackUP / backup.py

Full commit
FredGan 1848b37 
FredGan 5614f64 
FredGan 1848b37 



FredGan 206e200 
FredGan 1848b37 
FredGan 799de46 
FredGan 5614f64 
FredGan 1848b37 
















FredGan 6acf20b 
FredGan 1848b37 
FredGan c1e1dcf 
FredGan 206e200 
FredGan c50c427 
FredGan 1848b37 
FredGan 206e200 
FredGan c1e1dcf 

FredGan 799de46 



FredGan 6acf20b 
FredGan 799de46 
FredGan 206e200 

FredGan 1848b37 
FredGan c1e1dcf 


FredGan 5614f64 
FredGan c50c427 
FredGan 1848b37 

FredGan c50c427 
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##########################################################################
#BACKUP FILES company "AlieParusa"                                       #
##########################################################################
import xml.parsers.expat
import logging
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')
    #Create logg objects
    logging.basicConfig(filename=archivepach+'logs'+'_'+date+'.log',format='%(asctime)s %(message)s',level=logging.DEBUG)
    body=''
    for i in paths:
        logging.info('Start task: '+str(i))
        archname=archivepach+str(i)+'_'+date+".tar"
        tar = tarfile.open(archname, "w")
        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:
                      logging.warning("Error: "+fullpath)
        logging.info('Finish task: '+str(i))
        tar.close()
        # Email body include: name and size of file 'os.stat(archname).st_size'
        size = os.stat(archname).st_size/1048576 
        body=body+'Job '+str(i)+' is done.'+'Size:'+str(size)+'Mb'+'\n'
#Send email          
    modules.Sendemail(fro_m='service@redsails.ru', to='backup@redsails.ru', body=body , subject='BackUP')
#Run processing
Archive(Path())
modules.Rotation(Path())