Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Anders Blomdell
hash_backup
Commits
ebfecd55
Commit
ebfecd55
authored
Jul 07, 2016
by
Anders Blomdell
Browse files
Change to star instead of cpio to handle larger files.
parent
38879834
Changes
2
Hide whitespace changes
Inline
Side-by-side
primary.py
View file @
ebfecd55
...
...
@@ -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
:
...
...
secondary.py
View file @
ebfecd55
...
...
@@ -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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment