@@ -22,34 +22,44 @@ class Tar:
2222 def __init__ (self , config , backup_base_dir ):
2323 self .config = config
2424 self .backup_base_dir = backup_base_dir
25- self .compression = self .config .archive .compression
26- self .thread_count = self .config .archive .threads
2725 self .verbose = self .config .verbose
2826 self .binary = "tar"
27+ self .do_gzip = False
28+ self ._pool = None
2929
30- if self .thread_count is None or self .thread_count < 1 :
31- self .thread_count = cpu_count ()
30+ def compression (self , method = None ):
31+ if method :
32+ self .config .archive .tar .compression = method .lower ()
33+ return self .config .archive .tar .compression
3234
35+ def threads (self , thread_count = None ):
36+ if thread_count :
37+ self .config .archive .tar .threads = int (thread_count )
38+ logging .info ("Setting tar thread count to: %i" % self .config .archive .tar .threads )
39+ if self .config .archive .tar .threads is None or self .config .archive .tar .threads < 1 :
40+ self .config .archive .tar .threads = cpu_count ()
41+ return int (self .config .archive .tar .threads )
42+
43+ def run (self ):
3344 try :
34- self ._pool = Pool (processes = self .thread_count )
45+ thread_count = self .threads ()
46+ self ._pool = Pool (processes = thread_count )
47+ logging .info ("Archiving backup directories with pool of %i thread(s)" % thread_count )
3548 except Exception , e :
3649 logging .fatal ("Could not start pool! Error: %s" % e )
3750 raise e
3851
39- def run (self ):
40- logging .info ("Archiving backup directories with pool of %i thread(s)" % self .thread_count )
4152 if os .path .isdir (self .backup_base_dir ):
4253 try :
4354 for backup_dir in os .listdir (self .backup_base_dir ):
4455 subdir_name = "%s/%s" % (self .backup_base_dir , backup_dir )
4556 output_file = "%s.tar" % subdir_name
4657
47- do_gzip = False
48- if self .compression == "gzip" :
49- output_file = "%s.tgz" % subdir_name
50- do_gzip = True
58+ if self .compression () == 'gzip' :
59+ output_file = "%s.tgz" % subdir_name
60+ self .do_gzip = True
5161
52- self ._pool .apply_async (TarThread (subdir_name , output_file , do_gzip , self .verbose , self .binary ).run )
62+ self ._pool .apply_async (TarThread (subdir_name , output_file , self . do_gzip , self .verbose , self .binary ).run )
5363 except Exception , e :
5464 self ._pool .terminate ()
5565 logging .fatal ("Could not create archiving thread! Error: %s" % e )
@@ -59,8 +69,8 @@ def run(self):
5969 logging .info ("Archiver threads completed" )
6070
6171 def close (self ):
62- logging .info ( "Killing all Archiver threads... " )
72+ logging .debug ( "Stopping Archiver threads" )
6373 if self ._pool is not None :
6474 self ._pool .terminate ()
6575 self ._pool .join ()
66- logging .info ("Killed all Archiver threads" )
76+ logging .info ("Stopped all Archiver threads" )
0 commit comments