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