Commit 7e4739fe22e1ea3baee65d3129f0bd3a569f4817
Exists in
master
and in
4 other branches
Merge branch 'backup_commands' of /home/git/repositories/gitlab/gitlabhq
Showing
4 changed files
with
21 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
| 1 | 1 | module Backup |
| 2 | 2 | class Manager |
| 3 | + BACKUP_CONTENTS = %w{repositories/ db/ uploads/ backup_information.yml} | |
| 4 | + | |
| 3 | 5 | def pack |
| 4 | 6 | # saving additional informations |
| 5 | 7 | s = {} |
| ... | ... | @@ -16,7 +18,7 @@ module Backup |
| 16 | 18 | |
| 17 | 19 | # create archive |
| 18 | 20 | 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") | |
| 21 | + if Kernel.system('tar', '-cf', "#{s[:backup_created_at].to_i}_gitlab_backup.tar", *BACKUP_CONTENTS) | |
| 20 | 22 | puts "done".green |
| 21 | 23 | else |
| 22 | 24 | puts "failed".red |
| ... | ... | @@ -25,7 +27,7 @@ module Backup |
| 25 | 27 | |
| 26 | 28 | def cleanup |
| 27 | 29 | print "Deleting tmp directories ... " |
| 28 | - if Kernel.system("rm -rf repositories/ db/ uploads/ backup_information.yml") | |
| 30 | + if Kernel.system('rm', '-rf', *BACKUP_CONTENTS) | |
| 29 | 31 | puts "done".green |
| 30 | 32 | else |
| 31 | 33 | puts "failed".red |
| ... | ... | @@ -44,7 +46,7 @@ module Backup |
| 44 | 46 | file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ } |
| 45 | 47 | file_list.sort.each do |timestamp| |
| 46 | 48 | if Time.at(timestamp) < (Time.now - keep_time) |
| 47 | - if system("rm #{timestamp}_gitlab_backup.tar") | |
| 49 | + if Kernel.system(*%W(rm #{timestamp}_gitlab_backup.tar)) | |
| 48 | 50 | removed += 1 |
| 49 | 51 | end |
| 50 | 52 | end |
| ... | ... | @@ -75,7 +77,7 @@ module Backup |
| 75 | 77 | end |
| 76 | 78 | |
| 77 | 79 | print "Unpacking backup ... " |
| 78 | - unless Kernel.system("tar -xf #{tar_file}") | |
| 80 | + unless Kernel.system(*%W(tar -xf #{tar_file})) | |
| 79 | 81 | puts "failed".red |
| 80 | 82 | exit 1 |
| 81 | 83 | 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