33
34

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gitリポジトリ単位で バックアップ、アーカイブ、リカバリ

Posted at

やりたい事

  • リモートで管理しているgitリポジトリを丸ごとバックアップ、アーカイブ、リカバリしたかったのでメモ

実現するには…

  • バックアップ : --mirror オプションを付けて clone する
  • アーカイブ化 : clone したリポジトリをtarなどでアーカイブ化して保管
  • リカバリ方法 : --mirror=push オプションを付けて リモートリポジトリを作成

リモートリポジトリのバックアップ

  • --mirror オプションを付けてリモートリポジトリをclone
git clone --mirror "git@github/path/to/repo/repo.git" "/path/to/repo.git"
  • 通常のcloneとは異なり対象リポジトリの .git ディレクトリのみがCloneされる。
ls -al "/path/to/clone/repo.git"

アーカイブ化

  • --mirror でcloneしたディレクトリを丸ごと圧縮、保存してあれば後のリカバリに使える
  • tar.gz でアーカイブ化するなど...
tar -zcf "/path/to/archive.tar.gz" "/path/to/repo.git"

リポジトリをリモートリポジトリへ復元する

  • Clone済みの /path/to/repo.git ディレクトリへ移動してから作業する
cd "/path/to/repo.git"
  • --mirror オプションを付与して Pushする
git remote add --mirror=push origin "[email protected]"
git push origin
  • Pushしたリポジトリを別名でCloneしなおすなどで過去のコミットログの反映状況を確認する

その他

  • gitホスティングのサービス間でリポジトリを移動させたい場合に利用できる。
  • リポジトリ単位でバックアップ、アーカイブ化する用途に使える。

参考

33
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
34

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?