summaryrefslogtreecommitdiff
path: root/lib/backup/manager.rb
diff options
context:
space:
mode:
authorVinnie Okada <vokada@mrvinn.com>2015-03-22 21:50:28 -0600
committerVinnie Okada <vokada@mrvinn.com>2015-03-22 21:50:28 -0600
commit637ca0b388382112850fd3052a961bb07db34d14 (patch)
tree15f8abdad066ffcda26a49e645d8f8aee4571002 /lib/backup/manager.rb
parenta7afc0634240f5cddb6c6e1bf1f9fcf4374b852e (diff)
parentbc4e25189805879490555ef2782193470f4fe295 (diff)
downloadgitlab-ce-637ca0b388382112850fd3052a961bb07db34d14.tar.gz
Merge branch 'master' into markdown-tags
Diffstat (limited to 'lib/backup/manager.rb')
-rw-r--r--lib/backup/manager.rb43
1 files changed, 25 insertions, 18 deletions
diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb
index ab8db4e9837..c6087830b40 100644
--- a/lib/backup/manager.rb
+++ b/lib/backup/manager.rb
@@ -11,22 +11,27 @@ module Backup
s[:tar_version] = tar_version
tar_file = "#{s[:backup_created_at].to_i}_gitlab_backup.tar"
- Dir.chdir(Gitlab.config.backup.path)
+ Dir.chdir(Gitlab.config.backup.path) do
+ File.open("#{Gitlab.config.backup.path}/backup_information.yml",
+ "w+") do |file|
+ file << s.to_yaml.gsub(/^---\n/,'')
+ end
- File.open("#{Gitlab.config.backup.path}/backup_information.yml", "w+") do |file|
- file << s.to_yaml.gsub(/^---\n/,'')
- end
+ FileUtils.chmod_R(0700, %w{db uploads repositories})
- # create archive
- $progress.print "Creating backup archive: #{tar_file} ... "
- if Kernel.system('tar', '-cf', tar_file, *BACKUP_CONTENTS)
- $progress.puts "done".green
- else
- puts "creating archive #{tar_file} failed".red
- abort 'Backup failed'
- end
+ # create archive
+ $progress.print "Creating backup archive: #{tar_file} ... "
+ orig_umask = File.umask(0077)
+ if Kernel.system('tar', '-cf', tar_file, *BACKUP_CONTENTS)
+ $progress.puts "done".green
+ else
+ puts "creating archive #{tar_file} failed".red
+ abort 'Backup failed'
+ end
+ File.umask(orig_umask)
- upload(tar_file)
+ upload(tar_file)
+ end
end
def upload(tar_file)
@@ -51,11 +56,13 @@ module Backup
def cleanup
$progress.print "Deleting tmp directories ... "
- if Kernel.system('rm', '-rf', *BACKUP_CONTENTS)
- $progress.puts "done".green
- else
- puts "deleting tmp directory failed".red
- abort 'Backup failed'
+ BACKUP_CONTENTS.each do |dir|
+ if FileUtils.rm_rf(File.join(Gitlab.config.backup.path, dir))
+ $progress.puts "done".green
+ else
+ puts "deleting tmp directory '#{dir}' failed".red
+ abort 'Backup failed'
+ end
end
end