Restore a deleted repository for Bitbucket Server

Still need help?

The Atlassian Community is here for you.

Ask the community

Purpose

This page show the steps to restore the Git history for a deleted repository.

(warning) Repository details (including permissions, settings and hooks), pull requests (including their transition and comments) will not be restored. This procedure will only allow to restore the Git history.

Solution

Case #1 - recommended option

This option can be used if a backup of the repository, taken using one of the Data backup strategy, is available.

It is the recommended option because it is based on the repository backup available on the server. Compared to a cloned repository, this will contain all the branches and tags and not just the ones available on a local clone.


  • From the available backup, locate the bare repository that should be restored.
    Since Bitbucket Server 4.12.0, each repository contains a repository-config file that helps in identifying the repository slug and the project key. 
repository-config sample file
#>***********************************************
# THIS FILE IS MAINTAINED BY ATLASSIAN BITBUCKET
# IT CONTAINS NO USER-SERVICEABLE PARTS.
#>***********************************************
[bitbucket]
	hierarchy = <hierarchy id>
	project = <project key>
	repository = <repository slug>

For earlier versions, the missing repository can be identified by locating the missing folder in the $BITBUCKET_HOME/shared/data/repositories folder

  • Create a new repository in Bitbucket Server
  • Retrieve the repository clone URL from the Bitbucket Server
  • Browse into the directory containing the backup of the repository and run the following commands:

    # update the repository URL with the value of the newly created repository
    git remote add origin <new repository clone URL>
    
    
    # push the Git history (including branches and tags)
    git push --all origin
    git push --tags origin

Case #2

This option relies on a local clone available on a workstation of a Bitbucket Server, this may not contain the entire history as available on the server prior to the deletion.

Once a viable source repository has been identified, the steps to recreate the repository are the same as above.


Existing feature request

The feature request allowing a restore of a repository including all its details is available here: 

BSERV-4586 - Getting issue details... STATUS

Last modified on Nov 2, 2018

Was this helpful?

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