2016-04-14 14:57:25 +00:00
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class Saver
|
|
|
|
include Gitlab::ImportExport::CommandLineUtil
|
|
|
|
|
|
|
|
def self.save(*args)
|
|
|
|
new(*args).save
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(storage_path:)
|
|
|
|
@storage_path = storage_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
if compress_and_save
|
|
|
|
remove_storage_path
|
2016-05-03 09:13:10 +00:00
|
|
|
Rails.logger.info("Saved project export #{archive_file}")
|
2016-04-14 14:57:25 +00:00
|
|
|
archive_file
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def compress_and_save
|
|
|
|
tar_czf(archive: archive_file, dir: @storage_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_storage_path
|
|
|
|
FileUtils.rm_rf(@storage_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def archive_file
|
2016-04-22 10:18:11 +00:00
|
|
|
@archive_file ||= File.join(@storage_path, '..', "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_project_export.tar.gz")
|
2016-04-14 14:57:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|