-
-
Notifications
You must be signed in to change notification settings - Fork 740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add proof of concept for pull mechanism #6270
Open
qtc-de
wants to merge
1
commit into
borgbackup:master
Choose a base branch
from
qtc-de:feat/implement-pull-mechanism
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,7 +164,7 @@ class RepositoryServer: # pragma: no cover | |
'inject_exception', | ||
) | ||
|
||
def __init__(self, restrict_to_paths, restrict_to_repositories, append_only, storage_quota): | ||
def __init__(self, restrict_to_paths, restrict_to_repositories, append_only, storage_quota, pull_command=None): | ||
self.repository = None | ||
self.restrict_to_paths = restrict_to_paths | ||
self.restrict_to_repositories = restrict_to_repositories | ||
|
@@ -175,6 +175,7 @@ def __init__(self, restrict_to_paths, restrict_to_repositories, append_only, sto | |
self.append_only = append_only | ||
self.storage_quota = storage_quota | ||
self.client_version = parse_version('1.0.8') # fallback version if client is too old to send version information | ||
self.pull_command = pull_command | ||
|
||
def positional_to_named(self, method, argv): | ||
"""Translate from positional protocol to named protocol.""" | ||
|
@@ -194,13 +195,27 @@ def filter_args(self, f, kwargs): | |
return {name: kwargs[name] for name in kwargs if name in known} | ||
|
||
def serve(self): | ||
stdin_fd = sys.stdin.fileno() | ||
stdout_fd = sys.stdout.fileno() | ||
stderr_fd = sys.stdout.fileno() | ||
os.set_blocking(stdin_fd, False) | ||
os.set_blocking(stdout_fd, True) | ||
os.set_blocking(stderr_fd, True) | ||
|
||
if self.pull_command: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please reverse this, so that what we had in the past (push) is in the if-block and the new stuff is generally in the else-block? |
||
self.p = Popen(shlex.split(self.pull_command), bufsize=0, stdin=PIPE, stdout=PIPE, stderr=PIPE) | ||
|
||
stdin_fd = self.p.stdout.fileno() | ||
stdout_fd = self.p.stdin.fileno() | ||
stderr_fd = sys.stderr.fileno() | ||
os.set_blocking(stdin_fd, False) | ||
os.set_blocking(stdout_fd, False) | ||
os.set_blocking(stderr_fd, False) | ||
|
||
else: | ||
stdin_fd = sys.stdin.fileno() | ||
stdout_fd = sys.stdout.fileno() | ||
stderr_fd = sys.stdout.fileno() | ||
os.set_blocking(stdin_fd, False) | ||
os.set_blocking(stdout_fd, True) | ||
os.set_blocking(stderr_fd, True) | ||
|
||
unpacker = get_limited_unpacker('server') | ||
|
||
while True: | ||
r, w, es = select.select([stdin_fd], [], [], 10) | ||
if r: | ||
|
@@ -530,7 +545,7 @@ def required_version(self): | |
dictFormat = False # outside of __init__ for testing of legacy free protocol | ||
|
||
def __init__(self, location, create=False, exclusive=False, lock_wait=None, lock=True, append_only=False, | ||
make_parent_dirs=False, args=None): | ||
make_parent_dirs=False, args=None, serve=False): | ||
self.location = self._location = location | ||
self.preload_ids = [] | ||
self.msgid = 0 | ||
|
@@ -552,18 +567,28 @@ def __init__(self, location, create=False, exclusive=False, lock_wait=None, lock | |
testing = location.host == '__testsuite__' | ||
# when testing, we invoke and talk to a borg process directly (no ssh). | ||
# when not testing, we invoke the system-installed ssh binary to talk to a remote borg. | ||
env = prepare_subprocess_env(system=not testing) | ||
borg_cmd = self.borg_cmd(args, testing) | ||
if not testing: | ||
borg_cmd = self.ssh_cmd(location) + borg_cmd | ||
logger.debug('SSH command line: %s', borg_cmd) | ||
self.p = Popen(borg_cmd, bufsize=0, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) | ||
self.stdin_fd = self.p.stdin.fileno() | ||
self.stdout_fd = self.p.stdout.fileno() | ||
self.stderr_fd = self.p.stderr.fileno() | ||
os.set_blocking(self.stdin_fd, False) | ||
os.set_blocking(self.stdout_fd, False) | ||
os.set_blocking(self.stderr_fd, False) | ||
if serve: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also reverse blocks please. |
||
self.stdin_fd = sys.stdout.fileno() | ||
self.stdout_fd = sys.stdin.fileno() | ||
self.stderr_fd = sys.stderr.fileno() | ||
|
||
os.set_blocking(self.stdin_fd, True) | ||
os.set_blocking(self.stdout_fd, False) | ||
|
||
else: | ||
env = prepare_subprocess_env(system=not testing) | ||
borg_cmd = self.borg_cmd(args, testing) | ||
if not testing: | ||
borg_cmd = self.ssh_cmd(location) + borg_cmd | ||
logger.debug('SSH command line: %s', borg_cmd) | ||
self.p = Popen(borg_cmd, bufsize=0, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) | ||
self.stdin_fd = self.p.stdin.fileno() | ||
self.stdout_fd = self.p.stdout.fileno() | ||
self.stderr_fd = self.p.stderr.fileno() | ||
os.set_blocking(self.stdin_fd, False) | ||
os.set_blocking(self.stdout_fd, False) | ||
os.set_blocking(self.stderr_fd, False) | ||
|
||
self.r_fds = [self.stdout_fd, self.stderr_fd] | ||
self.x_fds = [self.stdin_fd, self.stdout_fd, self.stderr_fd] | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't that confusing?
the source of the data is always where the borg client runs and the destination of the data is where borg serve(r) runs (which feeds the data into the repo).
so the data is either pushed from client to server (what we ever did) or pulled from the client to the server.
but we never are "pulling from a borg server" (I guess you meant that the pulling action is executed on the server, but that is not really clear).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same applies for the PR text (which in the end needs to be refactored and moved into the documentation).
isn't is simpler/less confusing if we just define borg server == where "borg serve" runs (and usually where repo is located) and borg client == where the to-be-backed-up files are located == where the stuff is encrypted/compressed/etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the PR top-post text is confusing the hell out of me. is it just me? please re-read / re-write.