Back Up and Restore Data#
The IT documentation contains business-critical data -- network diagrams, contract information, credentials, and configurations. Data loss due to hardware failure, human error, or an attack can have serious consequences. That is why i-doit belongs in every backup strategy.
Three areas need to be backed up:
- Databases -- system and tenant database(s)
- Files -- the i-doit installation directory including uploaded documents
- System configuration -- Apache, PHP, MariaDB
Easiest way: system:tenant-export
Since i-doit v38, the console command system:tenant-export is available, which exports the database and files in a single step as a ZIP. For regular automated backups, this is the recommended method.
Backup via the Console (Recommended)#
Since version 38, the i-doit console offers the commands system:tenant-export and system:tenant-import. They export or import a complete tenant -- database and uploaded files -- in a ZIP package. This is the simplest and safest way for a complete backup.
Export (Create Backup)#
1 2 | |
This creates a ZIP archive in the i-doit directory containing both the database dump and all uploaded files.
Import (Restore Backup)#
1 2 3 4 5 6 7 | |
Options:
| parameter | Description |
|---|---|
--file | Path to the ZIP file from the export |
--tenant-database-name | Name of the tenant database |
--tenant-title | Display name of the tenant |
--with-system-settings | Also import system-wide settings |
--with-tenant-settings | Import tenant-specific settings |
--db-root-user / --db-root-pass | Database root credentials (needed to create the database) |
--db-host / --db-port | Database host and port (default: localhost:3306) |
Set Up as Cronjob#
For daily automatic backups:
1 2 | |
Store backups externally
A backup that only exists on the same server does not protect against hardware failures. Copy the ZIP files regularly to an external system -- via rsync, scp, or to a network share.
Manual Backup#
If you are running an older i-doit version or need more control over the backup process, you can also back up the database and files manually.
Back Up Databases#
Use mysqldump for the database export. During the backup, no one should be working with i-doit -- it is best to stop the web server:
1 2 3 4 5 6 7 8 | |
Also disable cronjobs during the backup.
Restore:
1 | |
Foreign Key Constraints
During restoration, MariaDB may abort with errno: 150 "Foreign key constraint is incorrectly formed". This happens because tables are restored individually and references to tables that do not yet exist are encountered.
Solution: Drop the databases before restoration:
1 2 | |
Back Up Files#
Back up the entire i-doit directory:
1 | |
Restore:
1 | |
Then check the file permissions:
1 | |
Back Up System Configuration#
Back up the configuration files for Apache, PHP, and MariaDB:
1 2 3 4 | |
Ideally, you have already documented and securely stored the customizations during installation.
Backup Script#
For a simple, automated backup you can use a bash script. An example can be found at Backup script for data and files.
Recommendation
For new installations (from v38 onwards), system:tenant-export as a cronjob is the simpler and more reliable solution because the database and files are backed up in a consistent package.
VM Snapshots#
i-doit often runs on a virtual machine. However, a snapshot during live operation is not a reliable backup -- the database holds data in memory that may not have been written to disk at the time of the snapshot.
If you want to use snapshots, stop the database first:
1 2 3 4 5 | |
VM snapshots are a good supplement but not a substitute for a regular backup.
Best Practices#
- Regularity -- back up daily, at minimum before every update
- Test restores -- a backup is only as good as the last successful restore test. Regularly restore on a test system
- Store externally -- backups do not belong on the same server. Copy them to a network share, a backup server, or encrypted to the cloud
- Encrypt -- when backups leave the premises, encrypt them (e.g., with
gpg). Your CMDB contains sensitive infrastructure data - Retention period -- keep multiple generations (e.g., 7 daily backups + 4 weekly backups) so you can restore older states as well
- Document -- record the restore process in writing so that colleagues can also perform a recovery in an emergency
For a complete migration to another server, read the article Migrating an installation on Linux.