|
1 | 1 | # Migration from IDO |
2 | 2 |
|
3 | | -The Icinga DB Migration commandline tool migrates history data from [IDO] to |
4 | | -Icinga DB. Or, more precisely: from the IDO SQL database to the Icinga DB one. |
5 | | - |
6 | | -!!! info |
7 | | - |
8 | | - Everything else is already populated by Icinga DB itself. |
9 | | - Only the past history data of existing IDO setups |
10 | | - isn't known to Icinga DB without migration from IDO. |
11 | | - |
12 | | -## Icinga DB |
13 | | - |
14 | | -1. Make sure Icinga DB is up, running and writing to its database. |
15 | | -2. Optionally disable Icinga 2's IDO feature. |
16 | | - |
17 | | -!!! warning |
18 | | - |
19 | | - Migration will cause duplicate Icinga DB events |
20 | | - for the period both IDO and Icinga DB are active. |
21 | | - Read on, there is a way to avoid that. |
22 | | - |
23 | | -## Configuration file |
24 | | - |
25 | | -Create a YAML file like this somewhere: |
26 | | - |
27 | | -```yaml |
28 | | -icinga2: |
29 | | - # Content of /var/lib/icinga2/icingadb.env |
30 | | - env: "da39a3ee5e6b4b0d3255bfef95601890afBADHEX" |
31 | | -# IDO database |
32 | | -ido: |
33 | | - type: pgsql |
34 | | - host: 192.0.2.1 |
35 | | - port: 5432 |
36 | | - database: icinga |
37 | | - user: icinga |
38 | | - password: CHANGEME |
39 | | - # Input time range |
40 | | - #from: 0 |
41 | | - #to: 2147483647 |
42 | | -# Icinga DB database |
43 | | -icingadb: |
44 | | - type: mysql |
45 | | - host: 2001:db8::1 |
46 | | - port: 3306 |
47 | | - database: icingadb |
48 | | - user: icingadb |
49 | | - password: CHANGEME |
| 3 | +Migrating from the IDO feature to Icinga DB starts by setting up Icinga DB. To |
| 4 | +do so, please follow the [installation instructions]. The Icinga DB feature can |
| 5 | +be enabled in parallel to the IDO, allowing you to perform the migration while |
| 6 | +the IDO is still running. |
| 7 | + |
| 8 | +After setting up Icinga DB, all Icinga objects and their current state should |
| 9 | +already show up in Icinga DB Web as this information is synced from Icinga 2. |
| 10 | +At this point, the old host and service history is missing in Icinga DB. If it |
| 11 | +is desired to keep it, this information has to be migrated explicitly from the |
| 12 | +old IDO database. To do so, follow the instructions below. |
| 13 | + |
| 14 | +## History |
| 15 | + |
| 16 | +To migrate history data from the [IDO] database, the Icinga DB Migration |
| 17 | +commandline tool is provided. If you have installed Icinga DB from our |
| 18 | +packages, it is automatically installed as well. |
| 19 | + |
| 20 | +### Preparing the Configuration |
| 21 | + |
| 22 | +Please take the [example configuration] as a starting point and copy it to the |
| 23 | +host you will perform the migration on. The following sections will guide you |
| 24 | +through how to adjust it for your needs. |
| 25 | + |
| 26 | +#### Environment ID |
| 27 | + |
| 28 | +Icinga DB allows writing multiple Icinga environments to the same database. |
| 29 | +Thus, you have to tell the migration tool for which environment you want to |
| 30 | +migrate the history. On each Icinga 2 node that has the Icinga DB feature |
| 31 | +enabled, the environment ID is written to the file |
| 32 | +`/var/lib/icinga2/icingadb.env`. Please use the contents of this file for the |
| 33 | +`env` option in the section `icinga2`. |
| 34 | + |
| 35 | +#### Database Connection |
| 36 | + |
| 37 | +The migration tool needs to access both the IDO and the Icinga DB databases. |
| 38 | +Please specify the connection details in the corresponding `ido` and `icingadb` |
| 39 | +sections of the configuration. |
| 40 | + |
| 41 | +Both the IDO and Icinga DB support MySQL and PostgreSQL. You can migrate from |
| 42 | +and to both types, including from one type to the other. |
| 43 | + |
| 44 | +#### Input Time Range |
| 45 | + |
| 46 | +The migration tool allows you to restrict the time range of the history events |
| 47 | +to be migrated. This is controlled by the options `from` and `to` in the `ido` |
| 48 | +section of the configuration. Both options can be set to Unix timestamps. |
| 49 | + |
| 50 | +It is recommended to set the `to` option to a cutoff time at which the history |
| 51 | +in the Icinga DB database switches from migrated events to events written |
| 52 | +directly by Icinga DB. If you kept running the IDO in parallel to Icinga DB and |
| 53 | +do not do this, there will be duplicate events for the time both were running. |
| 54 | + |
| 55 | +You can query the time of the first history event written by Icinga DB by |
| 56 | +running this query in its database: |
| 57 | + |
| 58 | +``` |
| 59 | +SELECT MIN(event_time)/1000 FROM history; |
50 | 60 | ``` |
51 | 61 |
|
52 | | -### Input time range |
| 62 | +In case you had trouble setting up Icinga DB or this is not the first time you |
| 63 | +are setting up Icinga DB, please make sure to double-check this timestamp and |
| 64 | +adjust it accordingly if it is not what you expect. |
53 | 65 |
|
54 | | -By default, everything is migrated. If you wish, you can restrict the input |
55 | | -data's start and/or end by giving `from` and/or `to` under `ido:` as Unix |
56 | | -timestamps (in seconds). |
| 66 | +!!! tip |
57 | 67 |
|
58 | | -Examples: |
| 68 | + You can convert between Unix timestamps and a human-readable format using the `date` command: |
59 | 69 |
|
60 | | -* Now: Run in a shell: `date +%s` |
61 | | -* One year ago: Run in a shell: `date -d -1year +%s` |
62 | | -* Icinga DB usage start time: Query the Icinga DB database: |
63 | | - `SELECT MIN(event_time)/1000 FROM history;` |
| 70 | + * Unix timestamp to readable date: `date -d @1667219820` |
| 71 | + * Current date/time to Unix timestamp: `date +%s` |
| 72 | + * Specific date/time to Unix timestamp: `date -d '2022-01-01 00:00:00' +%s` |
| 73 | + * Relative date/time to Unix timestamp: `date -d '-1 year' +%s` |
64 | 74 |
|
65 | | -The latter is useful for the range end to avoid duplicate events. |
| 75 | +Similarly, you can use `from` to limit how much old history gets migrated. |
66 | 76 |
|
67 | | -## Cache directory |
| 77 | +### Cache Directory |
68 | 78 |
|
69 | 79 | Choose a (not necessarily yet existing) directory for Icinga DB Migration's |
70 | 80 | internal cache. If either there isn't much to migrate or the migration |
71 | 81 | process won't be interrupted by a reboot (of the machine |
72 | 82 | Icinga DB migration/database runs on), `mktemp -d` is enough. |
73 | 83 |
|
74 | | -## Actual migration |
| 84 | +### Run the Migration |
75 | 85 |
|
76 | | -Run: |
| 86 | +To start the actual migration, execute the following command: |
77 | 87 |
|
78 | 88 | ```shell |
79 | 89 | icingadb-migrate -c icingadb-migration.yml -t ~/icingadb-migration.cache |
80 | 90 | ``` |
81 | 91 |
|
82 | | -In case of an interrupt re-run. |
| 92 | +In case this command was interrupted, you can run it again. It will continue |
| 93 | +where it left off and reuse the cache if it is still present. |
83 | 94 |
|
84 | 95 | !!! tip |
85 | 96 |
|
86 | 97 | If there is much to migrate, use e.g. tmux to |
87 | 98 | protect yourself against SSH connection losses. |
88 | 99 |
|
89 | | - |
| 100 | +[installation instructions]: 02-Installation.md |
90 | 101 | [IDO]: https://icinga.com/docs/icinga-2/latest/doc/14-features/#ido-database-db-ido |
| 102 | +[example configuration]: icingadb-migration.example.yml |
0 commit comments