1. Home
  2. Docs
  3. Backup Ninja
  4. User Guide
  5. Backups
  6. Restore

Restore

Restore the backup on the database host. Backup Ninja will provide a set of commands to be executed on the database host depending on the database version, backup method, encryption, and compression options.

When restoring a backup, it has two different approaches. Auto-restore which will be done by Backup Ninja and manual restore which is applicable for the decrypted type of backups.

For auto-restore, this can be done either in two kinds of approaches. You can do a manual setup for the auto-restore by clicking the button Restore Backup. The second one is going over the list of successful and completed backups and click the + (expand the backup list entry), then click the restore icon. By clicking the restore icon, the setup fields are auto-populated based on the information of the currently selected backup entry. Once you restore it, in the Backup List, the Latest Restores section will show up revealing the list of restored entries, its restore state, and a clickable option named see a log, for which when clicked, will display the logs (timestamp and series of events) of the restoration.

For encrypted backup, Backup Ninja will provide a decryption command as explained in Decrypt Backup.

For examples of how to perform backup restoration, check out Restoring.

mysqldump

To restore a mysqldump backup, use the following command:

$ cat {backup-file} | mysql -h127.0.0.1 -uroot -p

Where, {backup-file} is the decompressed and decrypted backup.

Percona Xtrabackup (xtrabackup)

The following steps must be performed by a privileged user (root/sudo):

1. To restore an xtrabackup, the backup must be streamed using xbstream to the respective MySQL data directory:

$ cat {backup-file} | xbstream -x -C /path/to/data-dir

Where, {backup-file} is the decompressed and decrypted backup.

2.  Assign correct ownership of the MySQL data directory:

$ chown -Rf mysql:mysql /path/to/data-dir

3. Restart the MySQL service to load the restored data:

$ systemctl restart mysql

MariaDB Backup (mariabackup)

The following steps must be performed by a privileged user (root/sudo):

1. To restore a mariabackup, the backup must be streamed using mbstream to the respective MariaDB data directory:

$ cat {backup-file} | mbstream -x -C /path/to/data-dir

Where, {backup-file} is the decompressed and decrypted backup.

2. Assign correct ownership of the MariaDB data directory:

$ chown -Rf mysql:mysql /path/to/data-dir

3. Restart the MariaDB service to load the restored data:

$ systemctl restart mariadb

pg_dumpall

$ PGPASSWORD='{password}' psql -h127.0.0.1 -Upostgres -f {backup-file}

Where {password} is the password for the Postgres database user and {backup-file} is the decompressed and decrypted backup.

pg_basebackup

Restoring pg_basebackup requires PostgreSQL downtime.

1. Stop PostgreSQL daemon:

$ systemctl stop postgresql

2. Move or remove the existing data directory:

$ rm -rf /path/to/data-dir/main/*

3. Extract the backup using tar and replace the main directory for PostgreSQL data directory as user postgres:

$ sudo -u postgres tar -xvC /path/to/data-dir/main -f {backup-file}

Where, {backup-file} is the decompressed and decrypted backup.

4. Start PostgreSQL daemon:

$ systemctl start postgresql

mongodump

To restore a mongodump backup, use the following command:

$ mongorestore --host=localhost --username={agent-db-user} --password --archive={backup-file}

Where, {backup-file} is the decompressed and decrypted backup and {agent-db-user} is the Backup Ninja database username.

Was this article helpful to you? Yes No