Commit a540ab429025695659bcfad50ae9943cca6c60a9
1 parent
f9b66aec
Exists in
master
and in
4 other branches
Remove Bourne shell from backup code
Showing
4 changed files
with
19 additions
and
15 deletions
Show diff stats
lib/backup/database.rb
... | ... | @@ -13,20 +13,20 @@ module Backup |
13 | 13 | def dump |
14 | 14 | case config["adapter"] |
15 | 15 | when /^mysql/ then |
16 | - system("mysqldump #{mysql_args} #{config['database']} > #{db_file_name}") | |
16 | + system('mysqldump', *mysql_args, config['database'], out: db_file_name) | |
17 | 17 | when "postgresql" then |
18 | 18 | pg_env |
19 | - system("pg_dump #{config['database']} > #{db_file_name}") | |
19 | + system('pg_dump', config['database'], out: db_file_name) | |
20 | 20 | end |
21 | 21 | end |
22 | 22 | |
23 | 23 | def restore |
24 | 24 | case config["adapter"] |
25 | 25 | when /^mysql/ then |
26 | - system("mysql #{mysql_args} #{config['database']} < #{db_file_name}") | |
26 | + system('mysql', *mysql_args, config['database'], in: db_file_name) | |
27 | 27 | when "postgresql" then |
28 | 28 | pg_env |
29 | - system("psql #{config['database']} -f #{db_file_name}") | |
29 | + system('psql', config['database'], '-f', db_file_name) | |
30 | 30 | end |
31 | 31 | end |
32 | 32 | |
... | ... | @@ -45,7 +45,7 @@ module Backup |
45 | 45 | 'encoding' => '--default-character-set', |
46 | 46 | 'password' => '--password' |
47 | 47 | } |
48 | - args.map { |opt, arg| "#{arg}='#{config[opt]}'" if config[opt] }.compact.join(' ') | |
48 | + args.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact | |
49 | 49 | end |
50 | 50 | |
51 | 51 | def pg_env | ... | ... |
lib/backup/manager.rb
... | ... | @@ -16,7 +16,7 @@ module Backup |
16 | 16 | |
17 | 17 | # create archive |
18 | 18 | print "Creating backup archive: #{s[:backup_created_at].to_i}_gitlab_backup.tar ... " |
19 | - if Kernel.system("tar -cf #{s[:backup_created_at].to_i}_gitlab_backup.tar repositories/ db/ uploads/ backup_information.yml") | |
19 | + if Kernel.system(*%W(tar -cf #{s[:backup_created_at].to_i}_gitlab_backup.tar repositories/ db/ uploads/ backup_information.yml)) | |
20 | 20 | puts "done".green |
21 | 21 | else |
22 | 22 | puts "failed".red |
... | ... | @@ -25,7 +25,7 @@ module Backup |
25 | 25 | |
26 | 26 | def cleanup |
27 | 27 | print "Deleting tmp directories ... " |
28 | - if Kernel.system("rm -rf repositories/ db/ uploads/ backup_information.yml") | |
28 | + if Kernel.system(*%W(rm -rf repositories/ db/ uploads/ backup_information.yml)) | |
29 | 29 | puts "done".green |
30 | 30 | else |
31 | 31 | puts "failed".red |
... | ... | @@ -44,7 +44,7 @@ module Backup |
44 | 44 | file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ } |
45 | 45 | file_list.sort.each do |timestamp| |
46 | 46 | if Time.at(timestamp) < (Time.now - keep_time) |
47 | - if system("rm #{timestamp}_gitlab_backup.tar") | |
47 | + if Kernel.system(*%W(rm #{timestamp}_gitlab_backup.tar)) | |
48 | 48 | removed += 1 |
49 | 49 | end |
50 | 50 | end |
... | ... | @@ -75,7 +75,7 @@ module Backup |
75 | 75 | end |
76 | 76 | |
77 | 77 | print "Unpacking backup ... " |
78 | - unless Kernel.system("tar -xf #{tar_file}") | |
78 | + unless Kernel.system(*%W(tar -xf #{tar_file})) | |
79 | 79 | puts "failed".red |
80 | 80 | exit 1 |
81 | 81 | else | ... | ... |
lib/backup/repository.rb
... | ... | @@ -18,7 +18,7 @@ module Backup |
18 | 18 | # Create namespace dir if missing |
19 | 19 | FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.path)) if project.namespace |
20 | 20 | |
21 | - if system("cd #{path_to_repo(project)} > /dev/null 2>&1 && git bundle create #{path_to_bundle(project)} --all > /dev/null 2>&1") | |
21 | + if system(*%W(git --git-dir=#{path_to_repo(project)} bundle create #{path_to_bundle(project)} --all), silent) | |
22 | 22 | puts "[DONE]".green |
23 | 23 | else |
24 | 24 | puts "[FAILED]".red |
... | ... | @@ -30,7 +30,7 @@ module Backup |
30 | 30 | print " * #{wiki.path_with_namespace} ... " |
31 | 31 | if wiki.empty? |
32 | 32 | puts " [SKIPPED]".cyan |
33 | - elsif system("cd #{path_to_repo(wiki)} > /dev/null 2>&1 && git bundle create #{path_to_bundle(wiki)} --all > /dev/null 2>&1") | |
33 | + elsif system(*%W(git --git-dir=#{path_to_repo(wiki)} bundle create #{path_to_bundle(wiki)} --all), silent) | |
34 | 34 | puts " [DONE]".green |
35 | 35 | else |
36 | 36 | puts " [FAILED]".red |
... | ... | @@ -53,7 +53,7 @@ module Backup |
53 | 53 | |
54 | 54 | project.namespace.ensure_dir_exist if project.namespace |
55 | 55 | |
56 | - if system("git clone --bare #{path_to_bundle(project)} #{path_to_repo(project)} > /dev/null 2>&1") | |
56 | + if system(*%W(git clone --bare #{path_to_bundle(project)} #{path_to_repo(project)}), silent) | |
57 | 57 | puts "[DONE]".green |
58 | 58 | else |
59 | 59 | puts "[FAILED]".red |
... | ... | @@ -63,7 +63,7 @@ module Backup |
63 | 63 | |
64 | 64 | if File.exists?(path_to_bundle(wiki)) |
65 | 65 | print " * #{wiki.path_with_namespace} ... " |
66 | - if system("git clone --bare #{path_to_bundle(wiki)} #{path_to_repo(wiki)} > /dev/null 2>&1") | |
66 | + if system(*%W(git clone --bare #{path_to_bundle(wiki)} #{path_to_repo(wiki)}), silent) | |
67 | 67 | puts " [DONE]".green |
68 | 68 | else |
69 | 69 | puts " [FAILED]".red |
... | ... | @@ -73,7 +73,7 @@ module Backup |
73 | 73 | |
74 | 74 | print 'Put GitLab hooks in repositories dirs'.yellow |
75 | 75 | gitlab_shell_user_home = File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") |
76 | - if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh #{Gitlab.config.gitlab_shell.repos_path}") | |
76 | + if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh", Gitlab.config.gitlab_shell.repos_path) | |
77 | 77 | puts " [DONE]".green |
78 | 78 | else |
79 | 79 | puts " [FAILED]".red |
... | ... | @@ -103,5 +103,9 @@ module Backup |
103 | 103 | FileUtils.rm_rf(backup_repos_path) |
104 | 104 | FileUtils.mkdir_p(backup_repos_path) |
105 | 105 | end |
106 | + | |
107 | + def silent | |
108 | + {err: '/dev/null', out: '/dev/null'} | |
109 | + end | |
106 | 110 | end |
107 | 111 | end | ... | ... |
lib/backup/uploads.rb