diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-04-10 15:41:47 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-04-10 15:41:47 +0300 |
commit | e230551940b31f7779a16975f2b3e941815d2e03 (patch) | |
tree | 9fff80e54dd1211888132032d59de20db4031762 /lib | |
parent | 1d03fa2e7f4d341f17d7ad5dcad4b1f8eda14a60 (diff) | |
download | gitlab-ce-e230551940b31f7779a16975f2b3e941815d2e03.tar.gz |
backup/restore uploads
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backup/uploads.rb | 25 | ||||
-rw-r--r-- | lib/tasks/gitlab/backup.rake | 22 |
2 files changed, 44 insertions, 3 deletions
diff --git a/lib/backup/uploads.rb b/lib/backup/uploads.rb new file mode 100644 index 00000000000..4a38af02522 --- /dev/null +++ b/lib/backup/uploads.rb @@ -0,0 +1,25 @@ +module Backup + class Uploads + attr_reader :app_uploads_dir, :backup_uploads_dir, :backup_dir + + def initialize + @app_uploads_dir = Rails.root.join('public', 'uploads') + @backup_dir = Gitlab.config.backup.path + @backup_uploads_dir = File.join(Gitlab.config.backup.path, 'uploads') + end + + # Copy uploads from public/uploads to backup/uploads + def dump + FileUtils.mkdir_p(backup_uploads_dir) + FileUtils.cp_r(app_uploads_dir, backup_dir) + end + + def restore + if File.exists?(app_uploads_dir) + FileUtils.mv(app_uploads_dir, Rails.root.join('public', "uploads.#{Time.now.to_i}")) + end + + FileUtils.cp_r(backup_uploads_dir, app_uploads_dir) + end + end +end diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake index 1f863424382..ad6ba43049c 100644 --- a/lib/tasks/gitlab/backup.rake +++ b/lib/tasks/gitlab/backup.rake @@ -9,6 +9,7 @@ namespace :gitlab do Rake::Task["gitlab:backup:db:create"].invoke Rake::Task["gitlab:backup:repo:create"].invoke + Rake::Task["gitlab:backup:uploads:create"].invoke Dir.chdir(Gitlab.config.backup.path) @@ -25,7 +26,7 @@ namespace :gitlab do # create archive print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar ... " - if Kernel.system("tar -cf #{Time.now.to_i}_gitlab_backup.tar repositories/ db/ backup_information.yml") + if Kernel.system("tar -cf #{Time.now.to_i}_gitlab_backup.tar repositories/ db/ uploads/ backup_information.yml") puts "done".green else puts "failed".red @@ -33,7 +34,7 @@ namespace :gitlab do # cleanup: remove tmp files print "Deleting tmp directories ... " - if Kernel.system("rm -rf repositories/ db/ backup_information.yml") + if Kernel.system("rm -rf repositories/ db/ uploads/ backup_information.yml") puts "done".green else puts "failed".red @@ -99,10 +100,11 @@ namespace :gitlab do Rake::Task["gitlab:backup:db:restore"].invoke Rake::Task["gitlab:backup:repo:restore"].invoke + Rake::Task["gitlab:backup:uploads:restore"].invoke # cleanup: remove tmp files print "Deleting tmp directories ... " - if Kernel.system("rm -rf repositories/ db/ backup_information.yml") + if Kernel.system("rm -rf repositories/ db/ uploads/ backup_information.yml") puts "done".green else puts "failed".red @@ -136,5 +138,19 @@ namespace :gitlab do puts "done".green end end + + namespace :uploads do + task :create => :environment do + puts "Dumping uploads ... ".blue + Backup::Uploads.new.dump + puts "done".green + end + + task :restore => :environment do + puts "Restoring uploads ... ".blue + Backup::Uploads.new.restore + puts "done".green + end + end end # namespace end: backup end # namespace end: gitlab |