Commit 7e4739fe authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'backup_commands' of /home/git/repositories/gitlab/gitlabhq

parents fd6e5161 36f3de4f
...@@ -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
......
module Backup module Backup
class Manager class Manager
BACKUP_CONTENTS = %w{repositories/ db/ uploads/ backup_information.yml}
def pack def pack
# saving additional informations # saving additional informations
s = {} s = {}
...@@ -16,7 +18,7 @@ module Backup ...@@ -16,7 +18,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('tar', '-cf', "#{s[:backup_created_at].to_i}_gitlab_backup.tar", *BACKUP_CONTENTS)
puts "done".green puts "done".green
else else
puts "failed".red puts "failed".red
...@@ -25,7 +27,7 @@ module Backup ...@@ -25,7 +27,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('rm', '-rf', *BACKUP_CONTENTS)
puts "done".green puts "done".green
else else
puts "failed".red puts "failed".red
...@@ -44,7 +46,7 @@ module Backup ...@@ -44,7 +46,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 +77,7 @@ module Backup ...@@ -75,7 +77,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