Vagrant plugin の Sahara をインストールして使ってみる

Saharaはvagrantのpluginでvmのスナップショット(?)というか復元ポイントを設定したり,ロールバックしたりすることが出来る. sandbox(砂場)とsaharaからサハラ砂漠からとったのかな? 巨大なお砂場です.

  • OSX: 10.7.5
  • VirtualBox: 4.3.0 r89960
  • Vagrant: 1.3.5
    • Sahara: 0.0.16

Saharaのインストール

vagrant 1.0.7 のときは,vagrant gem install saharaでインストールできたっぽいが, vagrant 1.3.5にはgemオプションがなかった. これかなと思って,pluginオプションを使ってみたらインストール出来ました.

vagrant plugin install sahara

Saharaの使い方

  • sandboxを有効にする(ロールバックした時にここまで戻る): vagrant sandbox on - sandboxを無効にする: vagrant sandbox off
  • sandboxの状態をみる: vagrant sandbox status
  • ロールバック: vagrant sandbox rollback
  • sandboxを有効にしてから変更した物を確定する: vagrant sandbox commit

ロールバック

$ vagrant sandbox on
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

$ ssh vag
Last login: Thu Oct 24 08:45:28 2013 from 10.0.2.2
[vagrant@localhost ~]$ ls
base.shcleanup.shvagrant.shvirtualbox.sh
[vagrant@localhost ~]$ touch hello_vag.txt
[vagrant@localhost ~]$ ls
base.shcleanup.sh  hello.txt  hello_vag.txt  vagrant.shvirtualbox.sh
[vagrant@localhost ~]$ logout
Connection to 127.0.0.1 closed.

 $ vagrant sandbox rollback
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

$ ssh vag
Last login: Thu Oct 24 08:45:28 2013 from 10.0.2.2
[vagrant@localhost ~]$ ls
base.shcleanup.shvagrant.shvirtualbox.sh

hello_vag.txtが作成されてないことになってる.

コミットせずにsandbox off

$ vagrant sandbox status
[default] Sandbox mode is on
$ ssh vag
Last login: Thu Oct 24 08:45:28 2013 from 10.0.2.2
[vagrant@localhost ~]$ ls
base.shcleanup.shvagrant.shvirtualbox.sh
[vagrant@localhost ~]$ touch hello_vag.txt
[vagrant@localhost ~]$ ls
base.shcleanup.sh  hello_vag.txt  vagrant.shvirtualbox.sh
[vagrant@localhost ~]$ logout
Connection to 127.0.0.1 closed.
$  vagrant sandbox off
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
$ ssh vag
Last login: Thu Oct 24 08:55:34 2013 from 10.0.2.2
[vagrant@localhost ~]$ ls
base.shcleanup.sh  hello_vag.txt  vagrant.shvirtualbox.sh
[vagrant@localhost ~]$ logout
Connection to 127.0.0.1 closed.
$ vagrant sandbox rollback
[default] Not sandbox mode now

$ vagrant sandbox rollback
[default] Not sandbox mode now

コミットせずにsandboxをoffにするとcommitされたことになるっぽい.

コミット

$ vagrant sandbox on
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
$ ssh vag
Last login: Thu Oct 24 09:02:28 2013 from 10.0.2.2
[vagrant@localhost ~]$ ls
base.shcleanup.sh  hello_vag.txt  vagrant.shvirtualbox.sh
[vagrant@localhost ~]$ rm -i hello_vag.txt
rm: remove 通常の空ファイル `hello_vag.txt'? ye
[vagrant@localhost ~]$ logout
Connection to 127.0.0.1 closed.
$ vagrant sandbox commit
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
$ ssh vag ls
base.sh
cleanup.sh
vagrant.sh
virtualbox.sh
$ vagrant sandbox rollback
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
$ ssh vag ls
base.sh
cleanup.sh
vagrant.sh
virtualbox.sh

コミットしたので,ロールバックしても消したファイルは消えたまま.

こんなかんじです.

参考