Backup and restore will be necessary when you are going to change MySQL, PostgreSQL or MongoDB versions. Each version has its own data directory and different versions do not pick up the databases from another version.
There are many different options to backup your MySQL database including some for the command line and some for using the Web interface. The recommended and fastest method is to use mysqldump-secure, as it will also add info files (`*.info`) to each database recording checksums, dump date, dump options and from which version the backup come from.
##### 2.1.1 mysqldump-secure
**[mysqldump-secure](https://mysqldump-secure.org)** is bundled, setup and ready to use in every PHP/HHVM container. You can run it without any arguments and it will dump each available database as a separated compressed file. Backups will be located in `./backups/mysql/` on the Docker host or in `/shared/backups/mysql/` inside the Docker container.
To find out more about the configuration and options of mysqldump-secure, visit its project page under: [https://mysqldump-secure.org](https://mysqldump-secure.org).
##### 2.1.2 mysqldump
**[mysqldump](https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html)** is bundled with each PHP/HHVM container and ready to use. To backup a database named `my_db_name` follow the below listed example:
devilbox@php-7.1.6 in /shared/httpd $ mysqldump -h mysql -u root -p my_db_name > /shared/backups/mysql/my_db_name.sql
```
To find out more about the configuration and options of mysqldump, visit its project page under: [https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html](https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html).
##### 2.1.3 phpMyAdmin
If you do not like to use the command line for backups, you can use **[phpMyAdmin](https://www.phpmyadmin.net)**. It comes bundled with the devilbox intranet. View [Usage](Usage.md) to read more about the devilbox intranet.
To find out more about the usage of phpMyAdmin, visit its project page under: [https://www.phpmyadmin.net](https://www.phpmyadmin.net).
##### 2.1.4 Adminer
If you do not like to use the command line for backups, you can use **[Adminer](https://www.adminer.org)**. It comes bundled with the devilbox intranet. View [Usage](Usage.md) to read more about the devilbox intranet.
To find out more about the usage of Adminer, visit its project page under: [https://www.adminer.org](https://www.adminer.org).
#### 2.2 MySQL Database Restore
##### 2.2.1 mysql
In order to restore or import mysql databases on the command line, you need to use `mysql`. Here are a few examples for different file types:
devilbox@php-7.1.6 in /shared/httpd $ tar xzOf /shared/backups/mysql/my_db_name.sql.tar.gz | mysql -h mysql -u root -p my_db_name
```
##### 2.2.2 phpMyAdmin
**[phpMyAdmin](https://www.phpmyadmin.net)** supports importing of many different formats out-of-the-box. Simply select the compressed or uncompressed file and press `Go` in the Web interface.
##### 2.2.3 Adminer
**[Adminer](https://www.adminer.org)** supports importing of plain (`*.sql`) or gzipped compressed (`*.sql.gz`) files out-of-the-box. Simply select the compressed or uncompressed file and press `Execute` in the Web interface.
## 3. PostgreSQL
#### 3.1 PostgreSQL Database Backup
##### 3.1.1 pg_dump
**[pg_dump](https://www.postgresql.org/docs/current/static/backup-dump.html)** is bundled with each PHP/HHVM container and ready to use. To backup a database named `my_db_name` follow the below listed example:
To find out more about the configuration and options of pg_dump, visit its project page under: [https://www.postgresql.org/docs/current/static/backup-dump.html](https://www.postgresql.org/docs/current/static/backup-dump.html#BACKUP-DUMP).
##### 3.1.2 Adminer
If you do not like to use the command line for backups, you can use **[Adminer](https://www.adminer.org)**. It comes bundled with the devilbox intranet. View [Usage](Usage.md) to read more about the devilbox intranet.
To find out more about the usage of Adminer, visit its project page under: [https://www.adminer.org](https://www.adminer.org).
#### 3.2 PostgreSQL Database Restore
##### 3.2.1 psql
In order to restore or import PostgreSQL databases on the command line, you need to use **[psql](https://www.postgresql.org/docs/current/static/backup-dump.html#BACKUP-DUMP-RESTORE)**. Here are a few examples for different file types:
devilbox@php-7.1.6 in /shared/httpd $ tar xzOf /shared/backups/pgsql/my_db_name.sql.tar.gz | psql -h pgsql -U postgres -W my_db_name
```
##### 3.2.2 Adminer
**[Adminer](https://www.adminer.org)** supports importing of plain (`*.sql`) or gzipped compressed (`*.sql.gz`) files out-of-the-box. Simply select the compressed or uncompressed file and press `Execute` in the Web interface.
**[mongodump](https://docs.mongodb.com/manual/reference/program/mongodump/)** is bundled with each PHP/HHVM container and ready to use. To backup all MongoDB databases follow the below listed example:
devilbox@php-7.1.6 in /shared/httpd $ mongodump --out /shared/backups/mongo
```
To find out more about the configuration and options of mongodump, visit its project page under: [https://docs.mongodb.com/manual/reference/program/mongodump/](https://docs.mongodb.com/manual/reference/program/mongodump/).
#### 4.2 MongoDB Database Restore
##### 4.2.1 mongorestore
**[mongorestore](https://docs.mongodb.com/manual/reference/program/mongorestore/)** is bundled with each PHP/HHVM container and ready to use. To restore all MongoDB databases follow the below listed example:
# Start the restore/import from /shared/backups/mongo
devilbox@php-7.1.6 in /shared/httpd $ mongorestore /shared/backups/mongo
```
To find out more about the configuration and options of mongorestore, visit its project page under: [https://docs.mongodb.com/manual/reference/program/mongorestore/](https://docs.mongodb.com/manual/reference/program/mongorestore/).