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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With