2017-09-07 17:27:04 -04:00
|
|
|
require 'logger'
|
|
|
|
|
|
|
|
desc "GitLab | Migrate LFS objects to remote storage"
|
|
|
|
namespace :gitlab do
|
|
|
|
namespace :lfs do
|
|
|
|
task migrate: :environment do
|
|
|
|
logger = Logger.new(STDOUT)
|
|
|
|
logger.info('Starting transfer of LFS files to object storage')
|
|
|
|
|
|
|
|
LfsObject.with_files_stored_locally
|
|
|
|
.find_each(batch_size: 10) do |lfs_object|
|
2019-03-13 09:42:43 -04:00
|
|
|
lfs_object.file.migrate!(LfsObjectUploader::Store::REMOTE)
|
|
|
|
|
|
|
|
logger.info("Transferred LFS object #{lfs_object.oid} of size #{lfs_object.size.to_i.bytes} to object storage")
|
|
|
|
rescue => e
|
|
|
|
logger.error("Failed to transfer LFS object #{lfs_object.oid} with error: #{e.message}")
|
2017-09-07 17:27:04 -04:00
|
|
|
end
|
|
|
|
end
|
2019-09-20 08:05:52 -04:00
|
|
|
|
|
|
|
task migrate_to_local: :environment do
|
|
|
|
logger = Logger.new(STDOUT)
|
|
|
|
logger.info('Starting transfer of LFS files to local storage')
|
|
|
|
|
|
|
|
LfsObject.with_files_stored_remotely
|
|
|
|
.find_each(batch_size: 10) do |lfs_object|
|
|
|
|
lfs_object.file.migrate!(LfsObjectUploader::Store::LOCAL)
|
|
|
|
|
|
|
|
logger.info("Transferred LFS object #{lfs_object.oid} of size #{lfs_object.size.to_i.bytes} to local storage")
|
|
|
|
rescue => e
|
|
|
|
logger.error("Failed to transfer LFS object #{lfs_object.oid} with error: #{e.message}")
|
|
|
|
end
|
|
|
|
end
|
2017-09-07 17:27:04 -04:00
|
|
|
end
|
|
|
|
end
|