gitlab-org--gitlab-foss/lib/gitlab/import_export/saver.rb

43 lines
900 B
Ruby
Raw Normal View History

module Gitlab
module ImportExport
class Saver
include Gitlab::ImportExport::CommandLineUtil
def self.save(*args)
new(*args).save
end
def initialize(shared:)
@shared = shared
end
def save
if compress_and_save
2016-05-11 12:51:25 +00:00
remove_export_path
Rails.logger.info("Saved project export #{archive_file}")
archive_file
else
false
end
rescue => e
@shared.error(e.message)
false
end
private
def compress_and_save
2016-05-11 12:51:25 +00:00
tar_czf(archive: archive_file, dir: @shared.export_path)
end
2016-05-11 12:51:25 +00:00
def remove_export_path
FileUtils.rm_rf(@shared.export_path)
end
def archive_file
2016-05-11 12:51:25 +00:00
@archive_file ||= File.join(@shared.export_path, '..', "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_project_export.tar.gz")
end
end
end
end