Commit ebfecd55 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Change to star instead of cpio to handle larger files.

parent 38879834
......@@ -46,7 +46,7 @@ class Server:
self.socket_path = '/tmp/%s_server' % (self.uuid)
self.mutex = threading.Lock()
self.thread_md5 = None
self.thread_cpio = None
self.thread_star = None
self.thread_server = threading.Thread(daemon=True, target=self.run)
self.thread_server.start()
......@@ -66,12 +66,12 @@ class Server:
args=(config_MD5_socket,))
self.thread_md5.start()
cpio_socket,_ = server.accept()
self.log.DEBUG('CPIO', cpio_socket)
star_socket,_ = server.accept()
self.log.DEBUG('CPIO', star_socket)
with self.mutex:
self.thread_md5 = threading.Thread(daemon=True,
target=self.run_cpio,
args=(cpio_socket,))
target=self.run_star,
args=(star_socket,))
self.thread_md5.start()
cond_unlink(self.socket_path, self.log)
......@@ -79,7 +79,7 @@ class Server:
def pending(self):
with self.mutex:
return ((self.thread_md5 and self.thread_md5.thread.is_alive()) or
(self.thread_cpio and self.thread_cpio.thread.is_alive()) or
(self.thread_star and self.thread_star.thread.is_alive()) or
(self.thread_server.is_alive()))
def send_MD5(self, config_MD5):
......@@ -102,23 +102,24 @@ class Server:
config_MD5.shutdown(socket.SHUT_RDWR)
config_MD5.close()
def run_cpio(self, cpio_socket):
self.log.DEBUG('START run_cpio',
def run_star(self, star_socket):
self.log.DEBUG('START run_star',
self.config.primary.mount.path,
self.path)
cmd = [ '/bin/cpio', '-oc', '--quiet' ]
cmd = [ '/bin/star', '-c', '-acl', '-Hexustar', '-list=-',
'-no-statistics' ]
cwd = os.path.join(self.config.primary.mount.path, self.path)
stdin = cpio_socket.makefile('rb')
stdout = cpio_socket.makefile('wb')
stdin = star_socket.makefile('rb')
stdout = star_socket.makefile('wb')
try:
subprocess.check_call(cmd, cwd=cwd,
stdin=stdin,
stdout=stdout,
stderr=self.log.makefile(encoding='utf-8'))
self.log.DEBUG('OK run_cpio', cmd, cwd)
self.log.DEBUG('OK run_star', cmd, cwd)
finally:
cpio_socket.shutdown(socket.SHUT_RDWR)
self.log.DEBUG('DONE run_cpio', cmd, cwd)
star_socket.shutdown(socket.SHUT_RDWR)
self.log.DEBUG('DONE run_star', cmd, cwd)
class Client:
......
......@@ -40,10 +40,10 @@ class Status:
class Backup:
def __init__(self, primary_cpio, mount, path, status, log):
self.primary_cpio = primary_cpio
self.primary_in = primary_cpio.makefile('wb')
self.primary_out = primary_cpio.makefile('rb')
def __init__(self, primary_star, mount, path, status, log):
self.primary_star = primary_star
self.primary_in = primary_star.makefile('wb')
self.primary_out = primary_star.makefile('rb')
self.mount = mount
self.path = path
self.status = status
......@@ -52,11 +52,7 @@ class Backup:
self.trash_root = os.path.join(mount, 'TRASH').encode('utf-8')
self.trash = os.path.join(self.trash_root,
str(int(time.time())).encode('utf-8'))
extract_cmd = [ '/bin/cpio',
'-idmu',
'--quiet',
'--no-absolute-filenames',
'--preserve-modification-time' ]
extract_cmd = [ '/bin/star', '-x', '-nowarn', '-no-statistics' ]
self.extract = subprocess.Popen(extract_cmd,
cwd=os.path.join(mount, path),
stdin=self.primary_out)
......@@ -64,7 +60,7 @@ class Backup:
def close(self):
self.primary_in.flush()
self.primary_cpio.shutdown(socket.SHUT_WR)
self.primary_star.shutdown(socket.SHUT_WR)
self.status.extract_OK = self.extract.wait()
def check(self, src, dst):
......@@ -177,11 +173,11 @@ def do_backup(options, socket_path, mount, path):
atexit.register(cond_kill, p)
dst = md5toc.MD5TOC(p.stdout)
# Connect to server cpio socket
primary_cpio = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
primary_cpio.connect(socket_path)
# Connect to server star socket
primary_star = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
primary_star.connect(socket_path)
backup = Backup(primary_cpio=primary_cpio,
backup = Backup(primary_star=primary_star,
mount=mount, path=path, status=status, log=log)
while True:
if src.name == None and dst.name == None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment