# Restore a local database dump

`localdump.sh restore [type]`

i.e.

`localdump.sh restore mysql`

to start interactive restore.

## Walk trough interactive mode

### Start restore

As root start the databse restore:

```txt
# /opt/imlbackup/client/localdump.sh restore mysql
...
```

### Select database dump to import

You get a listing of database schemes in the local backup folder.

```txt
========== select database ==========

icinga
icingadirector
icingaweb
information_schema
mysql
performance_schema
name of db to restore >
```

Followed by a prompt to name a database.

Hint: do not type here: if you are in a ssh terminal mark the database name with double click an paste it by right mouse key.

After selecting a database name you see its dumps named [dbname]__[timestamp].sql.gz.

```txt
name of db to restore >icingaweb

========== select a specific dump for that database ==========

-rw-r--r--. 1 root root 3568 Apr 13 23:04 icingaweb__20220413-2303.sql.gz
-rw-r--r--. 1 root root 3572 Apr 14 23:04 icingaweb__20220414-2303.sql.gz
-rw-r--r--. 1 root root 3573 Apr 15 23:04 icingaweb__20220415-2303.sql.gz
-rw-r--r--. 1 root root 3573 Apr 16 23:04 icingaweb__20220416-2303.sql.gz
-rw-r--r--. 1 root root 3574 Apr 17 23:04 icingaweb__20220417-2303.sql.gz
-rw-r--r--. 1 root root 3574 Apr 18 23:04 icingaweb__20220418-2303.sql.gz
-rw-r--r--. 1 root root 3575 Apr 19 23:04 icingaweb__20220419-2303.sql.gz
-rw-r--r--. 1 root root 3577 Apr 20 23:04 icingaweb__20220420-2303.sql.gz
backupset to import >
```

Copy and paste a filename with a timestamp that fits your needs.

```txt
backupset to import >icingaweb__20220420-2303.sql.gz
```

### Select target database

After selecting the file you will be asked where to import it.


```txt
backupset to import >icingaweb__20220420-2303.sql.gz

new database name [icingaweb] >

```

By default it will import the dump into its origin database.
But you can set another database name here.

```txt
new database name [icingaweb] >import_test
```

### Start import

After naming a target database the importer starts.

It

* drops an existing target database
* creates the database
* imports the dump

```txt
new database name [icingaweb] >import_test

db schema from param 2: [import_test]

import to import_test...

========== ensure that database exists ... ==========


========== import ... ==========

-rw-r--r--. 1 root root 3577 Apr 20 23:04 /var/iml-backup/mysql/icingaweb__20220420-2303.sql.gz
import to database [import_test]
OK
```

![Screenshot: interactive database import](./images/iml-backup-restore-local-db.png)

## Import without prompting

At the end of an interactive import you see the executed command line.

This you can use to write a batch importer:

/opt/imlbackup/client/localdump.sh restore /var/iml-backup/mysql/icingaweb__20220420-2303.sql.gz import_test 

The syntax is

`localdump.sh restore [type] [dumpfile]`

or 

`localdump.sh restore [type] [dumpfile] [target-db]`