2021-02-05 07:09:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-09-22 08:04:14 -04:00
|
|
|
namespace :gitlab do
|
|
|
|
namespace :git do
|
2017-12-14 05:49:35 -05:00
|
|
|
desc 'GitLab | Git | Check all repos integrity'
|
2018-01-24 03:12:33 -05:00
|
|
|
task fsck: :gitlab_environment do
|
2015-09-22 08:04:14 -04:00
|
|
|
failures = []
|
2018-07-24 06:17:29 -04:00
|
|
|
Project.find_each(batch_size: 100) do |project|
|
|
|
|
begin
|
|
|
|
project.repository.fsck
|
|
|
|
|
2021-04-26 08:09:44 -04:00
|
|
|
rescue StandardError => e
|
2018-07-24 06:17:29 -04:00
|
|
|
failures << "#{project.full_path} on #{project.repository_storage}: #{e}"
|
2015-10-01 07:34:41 -04:00
|
|
|
end
|
2018-01-03 08:51:04 -05:00
|
|
|
|
2018-07-24 06:17:29 -04:00
|
|
|
puts "Performed integrity check for #{project.repository.full_path}"
|
2015-09-22 08:04:14 -04:00
|
|
|
end
|
|
|
|
|
2018-07-24 06:17:29 -04:00
|
|
|
if failures.empty?
|
|
|
|
puts "Done".color(:green)
|
2018-01-03 08:51:04 -05:00
|
|
|
else
|
2018-07-24 06:17:29 -04:00
|
|
|
puts "The following repositories reported errors:".color(:red)
|
|
|
|
failures.each { |f| puts "- #{f}" }
|
2018-01-03 08:51:04 -05:00
|
|
|
end
|
|
|
|
end
|
2021-01-11 04:10:46 -05:00
|
|
|
|
|
|
|
# Example for all projects:
|
|
|
|
#
|
|
|
|
# $ bin/rake gitlab:git:checksum_projects
|
|
|
|
# 1,cfa3f06ba235c13df0bb28e079bcea62c5848af2
|
|
|
|
# 2,
|
|
|
|
# 3,3f3fb58a8106230e3a6c6b48adc2712fb3b6ef87
|
|
|
|
# 4,0000000000000000000000000000000000000000
|
|
|
|
#
|
|
|
|
# Example with a list of project IDs:
|
|
|
|
#
|
|
|
|
# $ CHECKSUM_PROJECT_IDS="1,3" bin/rake gitlab:git:checksum_projects
|
|
|
|
# 1,cfa3f06ba235c13df0bb28e079bcea62c5848af2
|
|
|
|
# 3,3f3fb58a8106230e3a6c6b48adc2712fb3b6ef87
|
|
|
|
#
|
|
|
|
# - If a repository does not exist, the project ID is output with a blank checksum
|
|
|
|
# - If a repository exists but is empty, the output checksum is `0000000000000000000000000000000000000000`
|
|
|
|
# - If given specific IDs, projects which do not exist are skipped
|
|
|
|
desc 'GitLab | Git | Generate checksum of project repository refs'
|
|
|
|
task checksum_projects: :environment do
|
|
|
|
project_ids = ENV['CHECKSUM_PROJECT_IDS']&.split(',')
|
|
|
|
relation = Project
|
|
|
|
relation = relation.where(id: project_ids) if project_ids.present?
|
|
|
|
|
|
|
|
relation.find_each(batch_size: 100) do |project|
|
|
|
|
next unless project.repo_exists?
|
|
|
|
|
|
|
|
result = project.repository.checksum
|
2021-04-26 08:09:44 -04:00
|
|
|
rescue StandardError => e
|
2021-01-11 04:10:46 -05:00
|
|
|
result = "Ignored error: #{e.message}".squish.truncate(255)
|
|
|
|
ensure
|
|
|
|
puts "#{project.id},#{result}"
|
|
|
|
end
|
|
|
|
end
|
2015-09-22 08:04:14 -04:00
|
|
|
end
|
|
|
|
end
|