etckeepr + github のプライベートリポジトリで /etc 以下をバックアップする

etckeepr + github のプライベートリポジトリで /etc 以下をバックアップする

etckeeper 導入

$ sudo apt-get install etckeeper

etckeeper 側で push 先を設定

diff --git a/etckeeper/etckeeper.conf b/etckeeper/etckeeper.conf
index f988c10..1fecf03 100644
--- a/etckeeper/etckeeper.conf
+++ b/etckeeper/etckeeper.conf
@@ -40,4 +40,4 @@ LOWLEVEL_PACKAGE_MANAGER=dpkg
 # To push each commit to a remote, put the name of the remote here.
 # (eg, "origin" for git). Space-separated lists of multiple remotes
 # also work (eg, "origin gitlab github" for git).
-PUSH_REMOTE=""
+PUSH_REMOTE="origin"

github でプライベートリポジトリを作成しておいてそれをリモートリポジトリに設定

$ cd /etc
$ sudo git remote add origin git@github.com:name/repo-name.git

鍵設定

ルート権限で push する様子なので /root/.ssh/ 以下に鍵を作成(もともと鍵がないか一応注意)。

$ sudo ls /root/.ssh/
known_hosts
$ sudo ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
...

root 用に ssh key を設定して プライペートリポジトリで鍵を追加する。「Allow write access」にチェックが入れられるのでそのリポジトリだけに書き込み権限を追加した鍵を設定することができる(現状ここは bitbucket ではできない)。

f:id:nise_nabe:20160513102229p:plain

最後に

人のサーバとかで鍵を置きたくない場合などにリポジトリ単位で鍵が設定できる github 便利。 プライベートリポジトリ無制限になりさらに便利。 そしてわりと簡単に導入できて apt でアップデートしたり cron.daily だったりで自動的にコミットとプッシュがされる etckeeper 便利。

参考

github.com

qiita.com