Migration

如何將所有儲存庫從 gitlab 遷移到 bitbucket

  • September 12, 2017

我的公司正在評估 bitbucket 作為我們的中心 VCS。我們目前使用 gitlab 7.13.4。我們一直在尋找一種自動化的方法來將我們所有的 gitlab 儲存庫遷移到 bitbucket,但我的搜尋結果是空的。有很多例子可以一次做一個,但沒有什麼可以批量做所有的。對於數百個儲存庫,我們希望使用一個具有良好可靠性的過程。

作為獎勵,有沒有辦法自動遷移組和權限?

您可以使用 Bit Bucket REST api,這是我用來將儲存庫導入 bitbucket 的一些 Perl:

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;
use File::Basename;
my $numArgs = $#ARGV + 1;

if($numArgs < 2) {
die "Usage: $0 [Bit Bucket Project e.g. FW, BDPE] [repo name] [-d dry run (optional)]";
}

my $bitbucketProject = lc $ARGV[0];
my $repoName = $ARGV[1];
my $dryRun = $ARGV[2];
my %moduleHash;
my $bitBucketServer = "localhost";
my $user = "admin";
my $password = "bitbucket";


print "Bit Bucket Project: $bitbucketProject\n";
print "Repository name: $repoName\n";

sub importRepo {

    my $command = sprintf("curl -u %s:%s -X POST -H \"Content-Type: application/json\" -d '{
    \"name\": \"%s\",
    \"scmId\": \"git\",
    \"forkable\": true
    \}' http://%s:7990/rest/api/1.0/projects/%s/repos", $user, $password, $repoName, $bitBucketServer, $bitbucketProject); 

   if ($dryRun) {
     print "$command\n";
   } else {
   print "Doing import\n";
       system $command;
   }
   my $bitbucketUrl = sprintf("ssh://git\@%s:7999/%s/%s.git", $bitBucketServer, lc $bitbucketProject, $repoName);   
   my $gitCommand = sprintf("cd %s; pwd;  git repack -a -d -f; git push %s --mirror", $repoName, $bitbucketUrl);
   if ($dryRun) {
     print "$gitCommand\n";
   } else {   
      print "Running git\n";
      system $gitCommand;
   }

}

importRepo();

然後你可以用一個 shell 腳本來解決它:

#!/bin/bash

BITBUCKETPROJECT=$1

if [ $# -ne 2 ]; then
echo "Usage: $0 [Bit Bucket Project] [Path to repos]"
exit 1;
fi

echo "Bit bucket project: $BITBUCKETPROJECT"

   for f in *; do
       if [[ -d $f ]]; then
         echo $f
         ./importRepository.pl $BITBUCKETPROJECT $f 
       fi
   done

假設您的所有儲存庫都已複製到目前目錄中。

https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html

引用自:https://serverfault.com/questions/833026