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,20 +13,20 @@ module Backup | ||
| 13 | def dump | 13 | def dump |
| 14 | case config["adapter"] | 14 | case config["adapter"] |
| 15 | when /^mysql/ then | 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 | when "postgresql" then | 17 | when "postgresql" then |
| 18 | pg_env | 18 | pg_env |
| 19 | - system("pg_dump #{config['database']} > #{db_file_name}") | 19 | + system('pg_dump', config['database'], out: db_file_name) |
| 20 | end | 20 | end |
| 21 | end | 21 | end |
| 22 | 22 | ||
| 23 | def restore | 23 | def restore |
| 24 | case config["adapter"] | 24 | case config["adapter"] |
| 25 | when /^mysql/ then | 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 | when "postgresql" then | 27 | when "postgresql" then |
| 28 | pg_env | 28 | pg_env |
| 29 | - system("psql #{config['database']} -f #{db_file_name}") | 29 | + system('psql', config['database'], '-f', db_file_name) |
| 30 | end | 30 | end |
| 31 | end | 31 | end |
| 32 | 32 | ||
| @@ -45,7 +45,7 @@ module Backup | @@ -45,7 +45,7 @@ module Backup | ||
| 45 | 'encoding' => '--default-character-set', | 45 | 'encoding' => '--default-character-set', |
| 46 | 'password' => '--password' | 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 | end | 49 | end |
| 50 | 50 | ||
| 51 | def pg_env | 51 | def pg_env |
lib/backup/manager.rb
| @@ -16,7 +16,7 @@ module Backup | @@ -16,7 +16,7 @@ module Backup | ||
| 16 | 16 | ||
| 17 | # create archive | 17 | # create archive |
| 18 | print "Creating backup archive: #{s[:backup_created_at].to_i}_gitlab_backup.tar ... " | 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 | puts "done".green | 20 | puts "done".green |
| 21 | else | 21 | else |
| 22 | puts "failed".red | 22 | puts "failed".red |
| @@ -25,7 +25,7 @@ module Backup | @@ -25,7 +25,7 @@ module Backup | ||
| 25 | 25 | ||
| 26 | def cleanup | 26 | def cleanup |
| 27 | print "Deleting tmp directories ... " | 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 | puts "done".green | 29 | puts "done".green |
| 30 | else | 30 | else |
| 31 | puts "failed".red | 31 | puts "failed".red |
| @@ -44,7 +44,7 @@ module Backup | @@ -44,7 +44,7 @@ module Backup | ||
| 44 | file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ } | 44 | file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ } |
| 45 | file_list.sort.each do |timestamp| | 45 | file_list.sort.each do |timestamp| |
| 46 | if Time.at(timestamp) < (Time.now - keep_time) | 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 | removed += 1 | 48 | removed += 1 |
| 49 | end | 49 | end |
| 50 | end | 50 | end |
| @@ -75,7 +75,7 @@ module Backup | @@ -75,7 +75,7 @@ module Backup | ||
| 75 | end | 75 | end |
| 76 | 76 | ||
| 77 | print "Unpacking backup ... " | 77 | print "Unpacking backup ... " |
| 78 | - unless Kernel.system("tar -xf #{tar_file}") | 78 | + unless Kernel.system(*%W(tar -xf #{tar_file})) |
| 79 | puts "failed".red | 79 | puts "failed".red |
| 80 | exit 1 | 80 | exit 1 |
| 81 | else | 81 | else |
lib/backup/repository.rb
| @@ -18,7 +18,7 @@ module Backup | @@ -18,7 +18,7 @@ module Backup | ||
| 18 | # Create namespace dir if missing | 18 | # Create namespace dir if missing |
| 19 | FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.path)) if project.namespace | 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 | puts "[DONE]".green | 22 | puts "[DONE]".green |
| 23 | else | 23 | else |
| 24 | puts "[FAILED]".red | 24 | puts "[FAILED]".red |
| @@ -30,7 +30,7 @@ module Backup | @@ -30,7 +30,7 @@ module Backup | ||
| 30 | print " * #{wiki.path_with_namespace} ... " | 30 | print " * #{wiki.path_with_namespace} ... " |
| 31 | if wiki.empty? | 31 | if wiki.empty? |
| 32 | puts " [SKIPPED]".cyan | 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 | puts " [DONE]".green | 34 | puts " [DONE]".green |
| 35 | else | 35 | else |
| 36 | puts " [FAILED]".red | 36 | puts " [FAILED]".red |
| @@ -53,7 +53,7 @@ module Backup | @@ -53,7 +53,7 @@ module Backup | ||
| 53 | 53 | ||
| 54 | project.namespace.ensure_dir_exist if project.namespace | 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 | puts "[DONE]".green | 57 | puts "[DONE]".green |
| 58 | else | 58 | else |
| 59 | puts "[FAILED]".red | 59 | puts "[FAILED]".red |
| @@ -63,7 +63,7 @@ module Backup | @@ -63,7 +63,7 @@ module Backup | ||
| 63 | 63 | ||
| 64 | if File.exists?(path_to_bundle(wiki)) | 64 | if File.exists?(path_to_bundle(wiki)) |
| 65 | print " * #{wiki.path_with_namespace} ... " | 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 | puts " [DONE]".green | 67 | puts " [DONE]".green |
| 68 | else | 68 | else |
| 69 | puts " [FAILED]".red | 69 | puts " [FAILED]".red |
| @@ -73,7 +73,7 @@ module Backup | @@ -73,7 +73,7 @@ module Backup | ||
| 73 | 73 | ||
| 74 | print 'Put GitLab hooks in repositories dirs'.yellow | 74 | print 'Put GitLab hooks in repositories dirs'.yellow |
| 75 | gitlab_shell_user_home = File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") | 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 | puts " [DONE]".green | 77 | puts " [DONE]".green |
| 78 | else | 78 | else |
| 79 | puts " [FAILED]".red | 79 | puts " [FAILED]".red |
| @@ -103,5 +103,9 @@ module Backup | @@ -103,5 +103,9 @@ module Backup | ||
| 103 | FileUtils.rm_rf(backup_repos_path) | 103 | FileUtils.rm_rf(backup_repos_path) |
| 104 | FileUtils.mkdir_p(backup_repos_path) | 104 | FileUtils.mkdir_p(backup_repos_path) |
| 105 | end | 105 | end |
| 106 | + | ||
| 107 | + def silent | ||
| 108 | + {err: '/dev/null', out: '/dev/null'} | ||
| 109 | + end | ||
| 106 | end | 110 | end |
| 107 | end | 111 | end |
lib/backup/uploads.rb
| @@ -19,7 +19,7 @@ module Backup | @@ -19,7 +19,7 @@ module Backup | ||
| 19 | 19 | ||
| 20 | FileUtils.cp_r(backup_uploads_dir, app_uploads_dir) | 20 | FileUtils.cp_r(backup_uploads_dir, app_uploads_dir) |
| 21 | end | 21 | end |
| 22 | - | 22 | + |
| 23 | def backup_existing_uploads_dir | 23 | def backup_existing_uploads_dir |
| 24 | if File.exists?(app_uploads_dir) | 24 | if File.exists?(app_uploads_dir) |
| 25 | FileUtils.mv(app_uploads_dir, Rails.root.join('public', "uploads.#{Time.now.to_i}")) | 25 | FileUtils.mv(app_uploads_dir, Rails.root.join('public', "uploads.#{Time.now.to_i}")) |