diff options
author | Ahmad Hassan <ahmad.hassan612@gmail.com> | 2018-06-13 12:19:17 +0300 |
---|---|---|
committer | Ahmad Hassan <ahmad.hassan612@gmail.com> | 2018-06-15 19:27:25 +0300 |
commit | 69de7b42cf7d3f0c99d63f1778f7f0b9d15ddfd8 (patch) | |
tree | 00da2a16a80c6c0f858358ceb170395a204317d8 /lib/gitlab | |
parent | c4a3587c7700eb4731502223e4683360454ed0d4 (diff) |
Migrate repo backup to gitaly
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/gitaly_client/repository_service.rb | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index 4340f779e53..ca986434221 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -196,20 +196,21 @@ module Gitlab end def create_bundle(save_path) - request = Gitaly::CreateBundleRequest.new(repository: @gitaly_repo) - response = GitalyClient.call( - @storage, - :repository_service, + gitaly_fetch_stream_to_file( + save_path, :create_bundle, - request, - timeout: GitalyClient.default_timeout + Gitaly::CreateBundleRequest, + GitalyClient.default_timeout ) + end - File.open(save_path, 'wb') do |f| - response.each do |message| - f.write(message.data) - end - end + def backup_custom_hooks(save_path) + gitaly_fetch_stream_to_file( + save_path, + :backup_custom_hooks, + Gitaly::BackupCustomHooksRequest, + GitalyClient.default_timeout + ) end def create_from_bundle(bundle_path) @@ -309,6 +310,25 @@ module Gitlab private + def gitaly_fetch_stream_to_file(save_path, rpc_name, request_class, timeout) + request = request_class.new(repository: @gitaly_repo) + response = GitalyClient.call( + @storage, + :repository_service, + rpc_name, + request, + timeout: timeout + ) + + File.open(save_path, 'wb') do |f| + response.each do |message| + f.write(message.data) + end + end + # If the file is empty means that we recieved an empty stream, we delete the file + FileUtils.rm(save_path) if File.zero?(save_path) + end + def gitaly_repo_stream_request(file_path, rpc_name, request_class, timeout) request = request_class.new(repository: @gitaly_repo) enum = Enumerator.new do |y| |