dix (Database Import eXport)

Submitted by gnikolovski on Sun, 03/19/2017 - 12:13

dix (Database Import eXport)

dix - Database Import eXport

dix is a simple console application that will make your life easier if you are working with MySQL databases. Let's say that you are working with some PHP framework or CMS, and that you want to test a new module/plugin/add-on, or maybe you want to upgrade to the latest version. The very first thing you should do is to make a backup of your database. Doing this will save you a lot of headache if something goes wrong.

Usually this means that you have to call mysql dump and export database somewhere on your disc. Although not a difficult task, it is error prone. Where to export a database file, how to name it, and how will you remember why you exported a database? These are just some questions to think about and consider when exporting a database. This is where dix will help you to save time.

When you install dix, you should first configure a directory where you will store your exported databases.

dix config --dir=/home/goran/backup/db

dix - Directory config

After you have your directory set up, you can start exporting databases. But you first have to decide whether you want to type database username and password every time you are making an export, or do you want to save credentials and avoid typing them in the future. If you want to configure database credentials once, you can use the config command.

dix config --dbname=website1 --user=db_user1 --pass=mystrongpassword

dix - Database credentials

Now you are ready to export your first database. Since you have database credential stored in the application configuration you can use the following command to export database:

dix export --dbname=website1 --msg="My first database export"

dix - Database export

Database file will be exported to the directory you specified before. Very useful option is that you can add message to your export. This way you have a description associated with the database, so you know why you exported it. Message is an optional argument, so you can omit it. You can see all your exports if you use the log command.

dix log

dix - Export log

Each export has a unique ID. This is used later, when you want to import a specific database. You can also search and filter log to find exactly what you want. Now lets say that your experiment failed, and that your database needs to be restored. You can do this just as easy. Use the following command:

dix import --dbname=website1

dix - Database import

This will import the last exported version of the "website1" database. If you want to import some other version of this database, you can specify its export log ID:

dix import --id=541265bfb223259ee62535c7e62c01f08ef14830

You don't have to enter all those characters. First five characters are enough:

dix import --id=54126

After executing this command you will be asked for the confirmation. Importing will overwrite the existing database, so be careful what are you doing. If you need the current database, then you should export it.

This article gives a general overview of dix. To see detailed explanation of all commands and arguments go to the Github project page where you can find all information you need about usage and installation.

Disclaimer: This application is still in the development phase, so make sure to use it only on your development machines. dix is provided "as is" without warranty of any kind, either expressed or implied.