Exporting GitLab model data in CSV format

GitLab model data can be exported from the DB to a csv file via the rails console. This can be handy if you need for example a list of users for an ISO audit. Running the script below inside the gitlab-rails console will output a CSV file named data.csv in the /tmp directory. with a list of users and their user ids.

require 'csv'

file = "/tmp/data.csv"
users = User.all 
column_names = ["User_ID","Name"]  

CSV.open( file, 'w' ) do |writer|
  writer << column_names
  users.each do |u|
    writer << [u.id, u.name]
  end
end
1 Like