How to find which repositories are actively being used

Still need help?

The Atlassian Community is here for you.

Ask the community

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

Summary

It's important for some teams to be able to report on which repositories in their system are actively being used for the purposes of archiving or removing old repositories that are no longer in use.

Environment

Bitbucket Server and Bitbucket Data Center.

Solution

While there's no kind of innate logging mechanism that accomplishes this request, it's possible to use the access logs in order to determine the number of requests made to a given repository.

  • (info) For example, the following bash script takes a given access log list ($FILESTOSCAN) and then outputs any git-upload-pack  operations found in the logs, and then groups them by the repository that the request was made against and outputs the 20 most-accessed repositories for the logs provided for HTTP and SSH independently.

FILESTOSCAN="atlassian-bitbucket-access*.log"

echo "Number of Clones per Repository"
echo "HTTP(s) clones:"
grep -h "git-upload-pack" $FILESTOSCAN | grep ", clone" | grep -v "SSH" | awk -F '|' '{ print $6 }' | awk -F ' ' '{ print $2 }' | awk -F '/' '{ print $3"/"$4 }' | sed "s/'//" | sort | uniq -c | sort -n -r | awk '{printf "%'\''d - %s\n", $1, $2 }' > clone_count.rpt
head -20 clone_count.rpt
echo "SSH Clones:"
grep -h "git-upload-pack" $FILESTOSCAN | grep ", clone" | grep "SSH" | awk -F '|' '{ print $6 }' | awk -F ' ' '{ print $4 }' | awk -F '/' '{ print $2"/"$3 }' | sed "s/'//" | sort | uniq -c | sort -n -r | awk '{printf "%'\''d - %s\n", $1, $2 }' > clone_count.rpt
head -20 clone_count.rpt

The above script is provided on a best-effort basis, and Atlassian Support is unable to directly support this script or any customizations made to it to achieve your team's business needs.

Last modified on Jun 29, 2021

Was this helpful?

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