summaryrefslogtreecommitdiff
path: root/lib/backup
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2013-11-05 15:00:48 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2013-11-06 14:02:28 +0100
commita540ab429025695659bcfad50ae9943cca6c60a9 (patch)
treebad474f03c00215acd9277e8ece39669a3c71f60 /lib/backup
parentf9b66aecddb248dcd501419e0ee94fd69fab4de3 (diff)
downloadgitlab-ce-a540ab429025695659bcfad50ae9943cca6c60a9.tar.gz
Remove Bourne shell from backup code
Diffstat (limited to 'lib/backup')
-rw-r--r--lib/backup/database.rb10
-rw-r--r--lib/backup/manager.rb8
-rw-r--r--lib/backup/repository.rb14
-rw-r--r--lib/backup/uploads.rb2
4 files changed, 19 insertions, 15 deletions
diff --git a/lib/backup/database.rb b/lib/backup/database.rb
index c4fb2e2e159..7af7140246a 100644
--- a/lib/backup/database.rb
+++ b/lib/backup/database.rb
@@ -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
diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb
index 258a0fb2589..3b2f525c0e4 100644
--- a/lib/backup/manager.rb
+++ b/lib/backup/manager.rb
@@ -16,7 +16,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(*%W(tar -cf #{s[:backup_created_at].to_i}_gitlab_backup.tar repositories/ db/ uploads/ backup_information.yml))
puts "done".green
else
puts "failed".red
@@ -25,7 +25,7 @@ module Backup
def cleanup
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
else
puts "failed".red
@@ -44,7 +44,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 +75,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
diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb
index 252201f11be..20fd5ba92a1 100644
--- a/lib/backup/repository.rb
+++ b/lib/backup/repository.rb
@@ -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
diff --git a/lib/backup/uploads.rb b/lib/backup/uploads.rb
index 462d3f1e274..e79da7e8fd2 100644
--- a/lib/backup/uploads.rb
+++ b/lib/backup/uploads.rb
@@ -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}"))