How to find personal repositories of deleted users

Still need help?

The Atlassian Community is here for you.

Ask the community

Summary

Admins sometimes need to find personal repositories of users who are no longer with their company or who have been removed from Bitbucket Server.

Solution

This workaround will provide you as the Bitbucket Server admin access to the repositories of removed users and give you the ability to either delete them or move them to a project of your choice.

Get a list of private repositories:

There are two SQL commands here that were created for MySQL. The basic concept is the same if you are on PostgreSQL, MS SQL Server, or Oracle but the actual SQL may need to be tweaked depending on your database type and the tool you are using to execute the SQL.

Prior to Bitbucket Server 7.0:

SELECT DETAILS, USER
FROM bitbucket.AO_BD73C3_REPOSITORY_AUDIT
Where USER IN 
 (
    SELECT USER_ID 
    FROM bitbucket.sta_normal_user 
    where deleted_timestamp 
    like '%'
    )
AND DETAILS like '%project%~%';

(info) Syntax for a PostgreSQL database

Syntax for Postgres...

In case you are using Postgres, make sure to quote the columns and the table names as in the example below, to force the usage of the uppercase for these values.

SELECT "DETAILS", "USER"
FROM "AO_BD73C3_REPOSITORY_AUDIT"
Where "USER" IN (
  SELECT user_id
  FROM sta_normal_user
  where deleted_timestamp is not null)
AND "DETAILS" like '%project%~%';


Alternative:

SELECT DETAILS, USER
FROM bitbucket.AO_BD73C3_REPOSITORY_AUDIT
Where USER IN 
 (
    SELECT USER_ID 
    FROM bitbucket.sta_normal_user 
    )
AND DETAILS like '%project%~%';
These SQL queries assume that the name of your database is "bitbucket". You will need to update the two FROM statements and replace bitbucket with the actual name of your database, and most DB types are case-sensitive.

In both of the SQL statements, the result will give you the username (prefixed with the ~) and the name of the repository.

From Bitbucket Server 7.0 onwards:

SELECT snu.name AS username, pr.name, pr.project_key, r.slug AS reposlug
FROM sta_personal_project spr, repository r, sta_normal_user snu, project pr
WHERE spr.project_id=r.project_id and spr.owner_id=snu.user_id  and pr.id=spr.project_id and pr.project_type=1

With this information you can do the following:

Prior to Stash/Bitbucket Server 3.9:

  1. Login to Bitbucket as an admin
  2. If you want to create a graveyard project create it now
  3. Modify the address line to something like http://<BITBUCKET_SERVER>:7990/users/<USER_NAME_FROM_SQL>. User name is all lower case and do not include the "~". 
    Example: http://localhost:7990/users/bob
  4. You will be given a list of all that users repositories (even if the user has been deleted)
  5. Click on the repository and then click Properties (gear icon under the project options)
  6. You now have the option to delete or move the repository to a public or private project.

From Stash/Bitbucket Server 3.9 onwards:

  1. Login to Bitbucket as an admin
  2. If you want to create a graveyard project create it now
  3. Access each repository found with the query directly, modifying the address line to something like http://<BITBUCKET_SERVER>:7990/projects/~<USER_NAME_FROM_SQL>/repos/<REPOSITORY_NAME>/browse
    Example: http://localhost:7990/projects/~BOB/repos/repository1/browse
  4. You'll access the repository settings page, which will give you the options to either move or delete the repository.

In addition, there's a feature suggestion for allowing System Administrators to easily view orphaned repositories, left by deleted users. You may check this at BSERV-7265 - Getting issue details... STATUS - feel free to vote and add any comments to it, as well as adding yourself as a watcher so you can track its progress directly. You may refer to the Implementation of New Features Policy.

Last modified on Jul 23, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.