メインコンテンツへスキップ

Vagrantの新しいスナップショットを検証

·376 文字·2 分
inamuu
著者
inamuu

環境
#

MacOS 10.11.3

Vagrantのバージョン
#

$ vagrant -v
Vagrant 1.8.1

プラグイン
#

$ vagrant plugin list
vagrant-share (1.1.5, system)

上記から見てわかる通り、スナップショットのプラグインは無いです。

コマンド
#

下記コマンドを実行して、ヘルプを表示させると、デフォルトでスナップショットが取得できることがわかります。
$ vagrant snapshot -h
Usage: vagrant snapshot []

Available subcommands:
delete
list
pop
push
restore
save

以前は「delete,go,take,list」などだったかと思いますが、「push,restore,save」が追加・変更されています。

それぞれのヘルプです。
$ vagrant snapshot delete -h
Usage: vagrant snapshot delete [options] [vm-name]

Delete a snapshot taken previously with snapshot save.

$ vagrant snapshot list -h
Usage: vagrant snapshot list [options] [vm-name]

List all snapshots taken for a machine.

$ vagrant snapshot pop -h
Usage: vagrant snapshot pop [options] [vm-name]

Restore state that was pushed with vagrant snapshot push.

$ vagrant snapshot push -h
Usage: vagrant snapshot push [options] [vm-name]

Take a snapshot of the current state of the machine and ‘push’
it onto the stack of states. You can use vagrant snapshot pop
to restore back to this state at any time.

If you use vagrant snapshot save or restore at any point after
a push, pop will still bring you back to this pushed state.

$ vagrant snapshot restore -h
Usage: vagrant snapshot restore [options] [vm-name]

Restore a snapshot taken previously with snapshot save.

$ vagrant snapshot save -h
Usage: vagrant snapshot save [options] [vm-name]

Take a snapshot of the current state of the machine. The snapshot
can be restored via vagrant snapshot restore at any point in the
future to get back to this exact machine state.

Snapshots are useful for experimenting in a machine and being able to rollback quickly.

スナップショットを取得する
#

単純にスナップショットを取得する場合は、「save」オプションでOKです。
なお、VMが起動中でも取得可能です。
$ vagrant snapshot save 1st-backup
==> default: Snapshotting the machine as ‘1st-backup’…
==> default: Snapshot saved! You can restore the snapshot at any time by
==> default: using vagrant snapshot restore. You can delete it using
==> default: vagrant snapshot delete.

確認。
$ vagrant snapshot list
1st-backup

取得したスナップショットへロールバックする
#

上記で取得した1st-backupをロールバックします。
この際、VMは自動的に再起動されます。
$ vagrant snapshot restore 1st-backup
==> default: Forcing shutdown of VM…
==> default: Restoring the snapshot ‘1st-backup’…
==> default: Resuming suspended VM…
==> default: Booting VM…
==> default: Waiting for machine to boot. This may take a few minutes…
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!

スナップショットを削除する
#

取得したスナップショットを削除します。
$ vagrant snapshot delete 1st-backup
==> default: Deleting the snapshot ‘1st-backup’…
==> default: Snapshot deleted!