How to obtain a list of all projects and repositories from Bitbucket database

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

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.

*Fisheye および Crucible は除く

目的

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.

ソリューション

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, named Temp1.
  • Project Project Two has one repository, named GitHook.
  • User internal1 has a personal repository, named PersonalRepo.

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';
  • MS SQL 

    MS SQL




    SELECT
          a.PRIMARY_RESOURCE_ID
        , a.ID
        , p.name
        , p.project_key
        , a.USER_ID
        , a.USER_NAME
        , a.ACTION
        , CAST(DATEADD(SECOND, a.ENTITY_TIMESTAMP / 1000, '1970/1/1') AS DATE) creation_date
    FROM AO_C77861_AUDIT_ENTITY a
        JOIN project p ON a.PRIMARY_RESOURCE_ID = p.id
    WHERE
        CAST(DATEADD(SECOND, a.ENTITY_TIMESTAMP / 1000, '1970/1/1') AS DATE) > '2023-12-30'
        AND a.[ACTION] in ('Project created', 'Repository created')
    ORDER BY a.ENTITY_TIMESTAMP DESC;







最終更新日: 2024 年 10 月 29 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.