mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-09 12:46:07 +10:00
Merge branch 'backup_commands' of /home/git/repositories/gitlab/gitlabhq
This commit is contained in:
@@ -13,20 +13,20 @@ module Backup
|
||||
def dump
|
||||
case config["adapter"]
|
||||
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
|
||||
pg_env
|
||||
system("pg_dump #{config['database']} > #{db_file_name}")
|
||||
system('pg_dump', config['database'], out: db_file_name)
|
||||
end
|
||||
end
|
||||
|
||||
def restore
|
||||
case config["adapter"]
|
||||
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
|
||||
pg_env
|
||||
system("psql #{config['database']} -f #{db_file_name}")
|
||||
system('psql', config['database'], '-f', db_file_name)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,7 +45,7 @@ module Backup
|
||||
'encoding' => '--default-character-set',
|
||||
'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
|
||||
|
||||
def pg_env
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
module Backup
|
||||
class Manager
|
||||
BACKUP_CONTENTS = %w{repositories/ db/ uploads/ backup_information.yml}
|
||||
|
||||
def pack
|
||||
# saving additional informations
|
||||
s = {}
|
||||
@@ -16,7 +18,7 @@ module Backup
|
||||
|
||||
# create archive
|
||||
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
|
||||
else
|
||||
puts "failed".red
|
||||
@@ -25,7 +27,7 @@ module Backup
|
||||
|
||||
def cleanup
|
||||
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
|
||||
else
|
||||
puts "failed".red
|
||||
@@ -44,7 +46,7 @@ module Backup
|
||||
file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ }
|
||||
file_list.sort.each do |timestamp|
|
||||
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
|
||||
end
|
||||
end
|
||||
@@ -75,7 +77,7 @@ module Backup
|
||||
end
|
||||
|
||||
print "Unpacking backup ... "
|
||||
unless Kernel.system("tar -xf #{tar_file}")
|
||||
unless Kernel.system(*%W(tar -xf #{tar_file}))
|
||||
puts "failed".red
|
||||
exit 1
|
||||
else
|
||||
|
||||
@@ -18,7 +18,7 @@ module Backup
|
||||
# Create namespace dir if missing
|
||||
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
|
||||
else
|
||||
puts "[FAILED]".red
|
||||
@@ -30,7 +30,7 @@ module Backup
|
||||
print " * #{wiki.path_with_namespace} ... "
|
||||
if wiki.empty?
|
||||
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
|
||||
else
|
||||
puts " [FAILED]".red
|
||||
@@ -53,7 +53,7 @@ module Backup
|
||||
|
||||
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
|
||||
else
|
||||
puts "[FAILED]".red
|
||||
@@ -63,7 +63,7 @@ module Backup
|
||||
|
||||
if File.exists?(path_to_bundle(wiki))
|
||||
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
|
||||
else
|
||||
puts " [FAILED]".red
|
||||
@@ -73,7 +73,7 @@ module Backup
|
||||
|
||||
print 'Put GitLab hooks in repositories dirs'.yellow
|
||||
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
|
||||
else
|
||||
puts " [FAILED]".red
|
||||
@@ -103,5 +103,9 @@ module Backup
|
||||
FileUtils.rm_rf(backup_repos_path)
|
||||
FileUtils.mkdir_p(backup_repos_path)
|
||||
end
|
||||
|
||||
def silent
|
||||
{err: '/dev/null', out: '/dev/null'}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,7 +19,7 @@ module Backup
|
||||
|
||||
FileUtils.cp_r(backup_uploads_dir, app_uploads_dir)
|
||||
end
|
||||
|
||||
|
||||
def backup_existing_uploads_dir
|
||||
if File.exists?(app_uploads_dir)
|
||||
FileUtils.mv(app_uploads_dir, Rails.root.join('public', "uploads.#{Time.now.to_i}"))
|
||||
|
||||
Reference in New Issue
Block a user