2013-04-10 08:41:47 -04:00
|
|
|
module Backup
|
|
|
|
class Uploads
|
2015-02-19 11:57:35 -05:00
|
|
|
attr_reader :app_uploads_dir, :backup_uploads_dir, :backup_dir
|
2013-04-10 08:41:47 -04:00
|
|
|
|
|
|
|
def initialize
|
2015-02-19 11:57:35 -05:00
|
|
|
@app_uploads_dir = File.realpath(Rails.root.join('public', 'uploads'))
|
2013-04-10 08:41:47 -04:00
|
|
|
@backup_dir = Gitlab.config.backup.path
|
2015-02-19 11:57:35 -05:00
|
|
|
@backup_uploads_dir = File.join(Gitlab.config.backup.path, 'uploads')
|
2013-04-10 08:41:47 -04:00
|
|
|
end
|
|
|
|
|
2015-02-19 11:57:35 -05:00
|
|
|
# Copy uploads from public/uploads to backup/uploads
|
2013-04-10 08:41:47 -04:00
|
|
|
def dump
|
2015-02-19 11:57:35 -05:00
|
|
|
FileUtils.mkdir_p(backup_uploads_dir)
|
|
|
|
FileUtils.cp_r(app_uploads_dir, backup_dir)
|
2013-04-10 08:41:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def restore
|
2015-02-19 11:57:35 -05:00
|
|
|
backup_existing_uploads_dir
|
2013-05-27 07:35:54 -04:00
|
|
|
|
2015-02-19 11:57:35 -05:00
|
|
|
FileUtils.cp_r(backup_uploads_dir, app_uploads_dir)
|
2013-05-27 07:35:54 -04:00
|
|
|
end
|
2013-11-05 09:00:48 -05:00
|
|
|
|
2015-02-19 11:57:35 -05:00
|
|
|
def backup_existing_uploads_dir
|
|
|
|
timestamped_uploads_path = File.join(app_uploads_dir, '..', "uploads.#{Time.now.to_i}")
|
|
|
|
if File.exists?(app_uploads_dir)
|
|
|
|
FileUtils.mv(app_uploads_dir, timestamped_uploads_path)
|
2013-04-10 08:41:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|