Commit a540ab42 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Remove Bourne shell from backup code

parent f9b66aec
...@@ -13,20 +13,20 @@ module Backup ...@@ -13,20 +13,20 @@ module Backup
def dump def dump
case config["adapter"] case config["adapter"]
when /^mysql/ then when /^mysql/ then
system("mysqldump #{mysql_args} #{config['database']} > #{db_file_name}") system('mysqldump', *mysql_args, config['database'], out: db_file_name)
when "postgresql" then when "postgresql" then
pg_env pg_env
system("pg_dump #{config['database']} > #{db_file_name}") system('pg_dump', config['database'], out: db_file_name)
end end
end end
def restore def restore
case config["adapter"] case config["adapter"]
when /^mysql/ then when /^mysql/ then
system("mysql #{mysql_args} #{config['database']} < #{db_file_name}") system('mysql', *mysql_args, config['database'], in: db_file_name)
when "postgresql" then when "postgresql" then
pg_env pg_env
system("psql #{config['database']} -f #{db_file_name}") system('psql', config['database'], '-f', db_file_name)
end end
end end
...@@ -45,7 +45,7 @@ module Backup ...@@ -45,7 +45,7 @@ module Backup
'encoding' => '--default-character-set', 'encoding' => '--default-character-set',
'password' => '--password' 'password' => '--password'
} }
args.map { |opt, arg| "#{arg}='#{config[opt]}'" if config[opt] }.compact.join(' ') args.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
end end
def pg_env def pg_env
......
...@@ -16,7 +16,7 @@ module Backup ...@@ -16,7 +16,7 @@ module Backup
# create archive # create archive
print "Creating backup archive: #{s[:backup_created_at].to_i}_gitlab_backup.tar ... " print "Creating backup archive: #{s[:backup_created_at].to_i}_gitlab_backup.tar ... "
if Kernel.system("tar -cf #{s[:backup_created_at].to_i}_gitlab_backup.tar repositories/ db/ uploads/ backup_information.yml") if Kernel.system(*%W(tar -cf #{s[:backup_created_at].to_i}_gitlab_backup.tar repositories/ db/ uploads/ backup_information.yml))
puts "done".green puts "done".green
else else
puts "failed".red puts "failed".red
...@@ -25,7 +25,7 @@ module Backup ...@@ -25,7 +25,7 @@ module Backup
def cleanup def cleanup
print "Deleting tmp directories ... " print "Deleting tmp directories ... "
if Kernel.system("rm -rf repositories/ db/ uploads/ backup_information.yml") if Kernel.system(*%W(rm -rf repositories/ db/ uploads/ backup_information.yml))
puts "done".green puts "done".green
else else
puts "failed".red puts "failed".red
...@@ -44,7 +44,7 @@ module Backup ...@@ -44,7 +44,7 @@ module Backup
file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ } file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ }
file_list.sort.each do |timestamp| file_list.sort.each do |timestamp|
if Time.at(timestamp) < (Time.now - keep_time) if Time.at(timestamp) < (Time.now - keep_time)
if system("rm #{timestamp}_gitlab_backup.tar") if Kernel.system(*%W(rm #{timestamp}_gitlab_backup.tar))
removed += 1 removed += 1
end end
end end
...@@ -75,7 +75,7 @@ module Backup ...@@ -75,7 +75,7 @@ module Backup
end end
print "Unpacking backup ... " print "Unpacking backup ... "
unless Kernel.system("tar -xf #{tar_file}") unless Kernel.system(*%W(tar -xf #{tar_file}))
puts "failed".red puts "failed".red
exit 1 exit 1
else else
......
...@@ -18,7 +18,7 @@ module Backup ...@@ -18,7 +18,7 @@ module Backup
# Create namespace dir if missing # Create namespace dir if missing
FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.path)) if project.namespace FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.path)) if project.namespace
if system("cd #{path_to_repo(project)} > /dev/null 2>&1 && git bundle create #{path_to_bundle(project)} --all > /dev/null 2>&1") if system(*%W(git --git-dir=#{path_to_repo(project)} bundle create #{path_to_bundle(project)} --all), silent)
puts "[DONE]".green puts "[DONE]".green
else else
puts "[FAILED]".red puts "[FAILED]".red
...@@ -30,7 +30,7 @@ module Backup ...@@ -30,7 +30,7 @@ module Backup
print " * #{wiki.path_with_namespace} ... " print " * #{wiki.path_with_namespace} ... "
if wiki.empty? if wiki.empty?
puts " [SKIPPED]".cyan puts " [SKIPPED]".cyan
elsif system("cd #{path_to_repo(wiki)} > /dev/null 2>&1 && git bundle create #{path_to_bundle(wiki)} --all > /dev/null 2>&1") elsif system(*%W(git --git-dir=#{path_to_repo(wiki)} bundle create #{path_to_bundle(wiki)} --all), silent)
puts " [DONE]".green puts " [DONE]".green
else else
puts " [FAILED]".red puts " [FAILED]".red
...@@ -53,7 +53,7 @@ module Backup ...@@ -53,7 +53,7 @@ module Backup
project.namespace.ensure_dir_exist if project.namespace project.namespace.ensure_dir_exist if project.namespace
if system("git clone --bare #{path_to_bundle(project)} #{path_to_repo(project)} > /dev/null 2>&1") if system(*%W(git clone --bare #{path_to_bundle(project)} #{path_to_repo(project)}), silent)
puts "[DONE]".green puts "[DONE]".green
else else
puts "[FAILED]".red puts "[FAILED]".red
...@@ -63,7 +63,7 @@ module Backup ...@@ -63,7 +63,7 @@ module Backup
if File.exists?(path_to_bundle(wiki)) if File.exists?(path_to_bundle(wiki))
print " * #{wiki.path_with_namespace} ... " print " * #{wiki.path_with_namespace} ... "
if system("git clone --bare #{path_to_bundle(wiki)} #{path_to_repo(wiki)} > /dev/null 2>&1") if system(*%W(git clone --bare #{path_to_bundle(wiki)} #{path_to_repo(wiki)}), silent)
puts " [DONE]".green puts " [DONE]".green
else else
puts " [FAILED]".red puts " [FAILED]".red
...@@ -73,7 +73,7 @@ module Backup ...@@ -73,7 +73,7 @@ module Backup
print 'Put GitLab hooks in repositories dirs'.yellow print 'Put GitLab hooks in repositories dirs'.yellow
gitlab_shell_user_home = File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") gitlab_shell_user_home = File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}")
if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh #{Gitlab.config.gitlab_shell.repos_path}") if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh", Gitlab.config.gitlab_shell.repos_path)
puts " [DONE]".green puts " [DONE]".green
else else
puts " [FAILED]".red puts " [FAILED]".red
...@@ -103,5 +103,9 @@ module Backup ...@@ -103,5 +103,9 @@ module Backup
FileUtils.rm_rf(backup_repos_path) FileUtils.rm_rf(backup_repos_path)
FileUtils.mkdir_p(backup_repos_path) FileUtils.mkdir_p(backup_repos_path)
end end
def silent
{err: '/dev/null', out: '/dev/null'}
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment