Source

Simple_BackUP / backup.py

FredGan 1848b37 































#!/usr/bin/env python
##########################################################################
#BACKUP FILES company "AlieParusa"                                       #
##########################################################################
import xml.parsers.expat
import tarfile
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
#Add item in archive
def Add_items(name, item):
    name.add(item)
#Create tar archives
def Archive(paths):
    date=datetime.now().strftime('%Y'"."'%m'"."'%d')
    for i in paths:
        tar = tarfile.open(str(i)+'_'+date+".tar", "w|gz")
        Add_items(tar,str(paths[i]))
        tar.close()
#Run processing
Archive(Path())