How to obtain a list of all projects and repositories from Bitbucket database
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Purpose
Whenever you have too many projects and too many repositories configured in the instance, having a better picture of how many of each you have can become challenging.
The purpose of this article is to help anybody that needs to retrieve a list of projects and repositories, along with personal repositories, directly from the database used by Bitbucket Server.
Advanced repository management available in Bitbucket Data Center 7.13
In 7.13, Bitbucket introduced Advanced repository management allowing you to more easily manage all of the repositories in your instance from the Repositories page in the Administration area.
Solution
Important Note on DB Queries
This Database Query / Functionality is not officially supported!
- Atlassian is not responsible for translating queries for different databases.
- This query should only be used as an example. Any desired adjustments should be checked with your local Database Administrator, including queries related to different DBMS that are not present/listed in this KB article, like Oracle Database.
- Atlassian will not be providing support for changes, adjustments, or inquiries regarding the below queries, as this is not part of our Atlassian Support Offerings.
- Atlassian does not provide any support to sample database queries provided in our Knowledge Base documents. Extraction of data from Bitbucket should be performed using our REST API Documentation because we do not keep all data relationships in the DB. Many connections to data are handled in the code. The REST API can go through the code paths to get the data. A SQL would have to do that manually or, in some cases, it can’t be done at all.
Connect to the database used by Bitbucket Server using the database vendor supplied tool or maybe using a client like DBVisualizer and run the following SQL query:
SELECT
prj.name AS "Project / User Name"
, prj.project_key AS "Project / User Key"
, rep.name AS "Repository Name"
, rep.slug AS "Repository Slug"
FROM repository rep
INNER JOIN project prj ON rep.project_id = prj.id
ORDER BY prj.name, rep.name
Sample result:
Project / User Name Project / User Key Repository Name Repository Slug
------------------- ------------------ --------------- ---------------
Project One PROJ Temp1 temp1
Project Two PT GitHook githook
~internal1 ~INTERNAL1 PersonalRepo personalrepo
Where
- Project
Project One
has one repository, namedTemp1
. - Project
Project Two
has one repository, namedGitHook
. - User
internal1
has a personal repository, namedPersonalRepo
.
If you would like to find out when a project or repository was created, you can use the queries below for Postgres and MSSQL databases:
Postgres
select p."name" , p.project_key , a."ACTION" , cast(to_timestamp(a."ENTITY_TIMESTAMP" / 1000) as date) creation_date , a."USER_NAME" from "AO_C77861_AUDIT_ENTITY" a , "project" p where a."PRIMARY_RESOURCE_ID" = cast(p.id as varchar(255)) and "ACTION" in ('Project created', 'Repository created') and cast(to_timestamp(a."ENTITY_TIMESTAMP" / 1000) as date) > '2023-12-31';
MSSQL