Vagrant - backup and restore environment

Posted on Wed 06 January 2016 by Pavlo Khmel

This post is related to previous post "Vagrant with multiple machines and ports".

1. Backup boxes

Remove file 70-persistent-net.rules on appsrv and monsrv before backup:

ssh -i ~/.vagrant.d/id_rsa vagrant@127.0.0.1 -p 3333 'sudo rm -f /etc/udev/rules.d/70-persistent-net.rules'
ssh -i ~/.vagrant.d/id_rsa vagrant@127.0.0.1 -p 4444 'sudo rm -f /etc/udev/rules.d/70-persistent-net.rules'

Stop environment:

cd ~/vagrant-homework/
vagrant halt

List VirtualBox VMs

$ vboxmanage list vms
"centos6" {ba7bbf9f-cf45-4872-a2b4-f4a6998e333a}
"vagrant-homework_appsrv_1445242618886_52097" {282d58e1-9894-4862-9699-81f8711c61b4}
"vagrant-homework_monsrv_1445242661704_79538" {6cec7ec4-5ab2-418e-befd-810f21e2fdc7}

Package appsrv and monsrv:

cd ~
vagrant package --output appsrv.box --base vagrant-homework_appsrv_1445242618886_52097
vagrant package --output monsrv.box --base vagrant-homework_monsrv_1445242661704_79538

Put all file in one archive:

cd ~
tar cf vagrant_env.tar .vagrant.d/id_rsa 
tar rf vagrant_env.tar appsrv.box 
tar rf vagrant_env.tar monsrv.box 
tar rf vagrant_env.tar vagrant-homework/

Share file vagrant_env.tar

2. Restore boxes

Download file vagrant_env.tar to your home directory on another host.

Start vagrant environment.

tar xf vagrant_env.tar
vagrant box add appsrv appsrv.box 
vagrant box add monsrv monsrv.box 
cd vagrant-homework/
vagrant up