summaryrefslogtreecommitdiff
path: root/lib/backup/uploads.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-10 15:41:47 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-10 15:41:47 +0300
commite230551940b31f7779a16975f2b3e941815d2e03 (patch)
tree9fff80e54dd1211888132032d59de20db4031762 /lib/backup/uploads.rb
parent1d03fa2e7f4d341f17d7ad5dcad4b1f8eda14a60 (diff)
downloadgitlab-ce-e230551940b31f7779a16975f2b3e941815d2e03.tar.gz
backup/restore uploads
Diffstat (limited to 'lib/backup/uploads.rb')
-rw-r--r--lib/backup/uploads.rb25
1 files changed, 25 insertions, 0 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