Store everything from a vagrant box

2019-07-26 23:00发布

I have a vagrant box (ubuntu 16.04) for development, and I made several apt install and some change to config files (.ini, .cnf, etc.) after initializing it. Now, I am OK with this box and its content. I want to save it before destroying everything by mistake.

I read this but I'm not sure to understand if it's really what I need. Does a snapshot store eveything? I mean does it save each installed programs, each edited conf and each files added in the shared /vagrant dir?

Doc speaks about "environment", that's why I am not sure it's what I want (side question if it's what I want: should I vagrant snapshot push or vagrant snapshot save?)

2条回答
Bombasti
2楼-- · 2019-07-26 23:41

vagrant package box should help you to create a new box.

Just note that since vagrant 1.7+ by default vagrant will change the ssh insecure keys, so if just package the box, it wont be able to connect on the next start up.

add the content of: https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub

into ~/.ssh/authorized_keys

and then run: chmod 600 /home/vagrant/.ssh/authorized_keys chown -R vagrant /home/vagrant/.ssh

查看更多
做自己的国王
3楼-- · 2019-07-26 23:47

You have 3 options to achieve what you want:

  • If you want to share the same environment with your teammates, you can package your VM as a new vagrant box (as explained by kikitux) so you can upload this box and your teammates will be install to spin a new VM based on your box (so they will have equivalent system)

  • If are able to put the changes you made into some scripts, a better option is to use vagrant provisioning (it can be bash script or more sophisticated chef/puppet system) - Its nice if you need to apply the same customization on another system, if you want to upgrade ubuntu for example, you can just apply the same provisioning script.

  • third, if you're local and just want to use that as a backup solution, the new feature vagrant snapshot is what you need. This has been a great addition in 1.8 version and does exactly what you need here.

Does a snapshot store eveything? I mean does it save each installed programs, each edited conf and each files added in the shared /vagrant dir?

Yep ! all this - I just share my use cases : I create an oracle database VM and import dump files and after I execute a series of test. I take a snapshot before I run the tests and I can easily revert back to the previous status and rerun tests the next day on the same base box. When I pop the snapshot I get the exact same status (whole VM, oracle installed, dump imported) as before I run the test suite.

side question if it's what I want: should I vagrant snapshot push or vagrant snapshot save?

I use push and pop because I only need to keep 1 snapshot and always revert back to this snapshot. If you need to keep snapshots at different times (for example one per day) you need to use save as you will specifically give a name for the snapshot you're taking.

Pay attention to this

Warning: If you are using push and pop, avoid using save and restore which are unsafe to mix.

查看更多
登录 后发表回答