1年前くらいまで使っていたGitLabのバックアップファイルに使いたいレポジトリがあるので残しておいたバックアップファイルから取得したレポジトリをGitHubに移動する。

以前はsakuraのベースサーバを借りてGitLabをインストールして使っていたが、1人で使うならGitHubのほうが安いなと思って2年前くらいに移行した記憶がある。その時、GitLabの中には10くらいレポジトリがあったがバックアップを取りGoogleDriveで放置していた。その中のSpringのレポジトリが参照したいのでバックアップから取り出してGitHubに移動させる。

おそらく以下のコマンドで生成されたGitLabのバックアップアーカイブ。

bundle exec rake gitlab:backup:create

アーカイブを展開

1446231610_gitlab_backup.tarという名前でバックアップが残されていた。

$ mkdir gitlab_backup
$ cp 1446231610_gitlab_backup.tar gitlab_backup/
$ cd gitlab_backup/
$ ls
1446231610_gitlab_backup.tar
$ tar xf 1446231610_gitlab_backup.tar
$ ls -l
合計 4028
-rw-rw-r-- 1 ishiis ishiis 4106240 8月 22 14:23 2016 1446231610_gitlab_backup.tar
-rw-r--r-- 1 ishiis ishiis 143 10月 31 04:00 2015 backup_information.yml
drwxr-xr-x 2 ishiis ishiis 4096 10月 31 04:00 2015 db
drwxr-xr-x 3 ishiis ishiis 4096 10月 31 04:00 2015 repositories
drwxr-xr-x 4 ishiis ishiis 4096 10月 31 04:00 2015 uploads

レポジトリを取り出す

.bundleという謎の拡張子が付いている。fileコマンドで調べるとGit bundleというタイプらしい。git bundleコマンドで生成できるファイルでgit pushコマンドで転送される同内容のデータを単一のバイナリファイルにまとめるそうです。

レポジトリの取り出しは.bundleを.gitとしてcloneする。中身を見てもいつものレポジトリっぽくない。もう一度Cloneするといつもの様なファイルが出てくる。それをGitHubにpushすればよい。

$ ls -l repositories/ishiis/
合計 3792
-rw-r--r-- 1 ishiis ishiis 3111688 10月 31 04:00 2015 tools.bundle
$ file repositories/ishiis/tools.bundle
repositories/ishiis/tools.bundle: Git bundle
$ git clone --mirror tools.bundle tools.git
$ git clone tools.git/ tools
$ cd tools
$ git remote set-url origin https://github.com/ishiis/********.git
$ git push origin master

おわり。

参考

  1. http://stackoverflow.com/questions/28838451/restore-gitlab-backup-repository-bundle-file-with-all-branches
  2. https://git-scm.com/book/ja/v2/Git-%E3%81%AE%E3%81%95%E3%81%BE%E3%81%96%E3%81%BE%E3%81%AA%E3%83%84%E3%83%BC%E3%83%AB-%E3%83%90%E3%83%B3%E3%83%89%E3%83%AB%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AE%E4%BD%9C%E6%88%90