Commits

FredGan committed 6acf20b

Добавил простое логирование

Comments (0)

Files changed (2)

    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):
+    archivepach="/usr/NAS/backups/"
     date=datetime.now().strftime('%Y'"."'%m'"."'%d')
     for i in paths:
-        tar = tarfile.open(str(i)+'_'+date+".tar", "w")
+        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:
-                      Add_items(tar,fullpath)
+                      tar.add(fullpath)
                 except:
-                      print fullpath
+                      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()
 #Run processing
 Archive(Path())
            <path tendo = "/mnt/tds"></path>
            <path domain = "/mnt/domain"></path>
            <path shuka = "/mnt/shuka"></path>
-           <path mail = "/mnt/mail"></path>
            <path kadri = "/mnt/kadri"></path>
            <path fileserver = "/mnt/fileserver"></path>
            <path it = "/mnt/it"></path>
            <path hoz_dog = "/mnt/hoz_dog"></path>
            <path com_dog = "/mnt/com_dog"></path>
-           <path alieparusa = "/mnt/alieparusa.ru"></path>
     </content>