Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep vagrant database data after vagrant destroy

What is the best/acceptable practice for keeping database data after a Vagrant destroy?

Should I create a shared folder for my database data? If so where (by default) does ubuntu store such data?

I forgot to mention my host and guest OS' are Ubuntu and am referring to MySql

like image 433
Tomeh Avatar asked Aug 26 '13 21:08

Tomeh


2 Answers

I needed a way to backup my database whenever I vagrant destroy the instance or if something happened with the box and I needed to kill the process thus loosing data. I primarily work with CMS systems and having the backend database persisted is very important.

I'm already sharing a db folder that contains a sql file that is used when provisioning. I installed the vagrant-triggers plugin and have it running a mysqldump.sh script file whenever I run the vagrant destroy command.

config.trigger.before :destroy do info "Dumping the database before destroying the VM..." run_remote "bash /home/vagrant/db/mysqldump.sh" end

The mysqldump.sh file runs a mysqldump command to a separate backup.sql file.

mysqldump -u root database > /home/vagrant/db/backup.sql

like image 57
raupie Avatar answered Nov 20 '22 15:11

raupie


It depends on the RDBMS you use.

For MySQL on Ubuntu, you can simply backup (tar or rsync to a remote host) the /var/lib/mysql folder (when mysql is NOT running) and its configuration files /etc/mysql.

For PostgreSQL it is similar, the database files are normally under cd /usr/local/pgsql/data. Refer to File System level backup

NOTE: avoid using the default vboxsf to share large number of files between guest and host because it has known performance issues.

like image 21
Terry Wang Avatar answered Nov 20 '22 14:11

Terry Wang