Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve backup restore to redis #1920

Closed
klein0r opened this issue May 18, 2022 · 3 comments · Fixed by #2388
Closed

Improve backup restore to redis #1920

klein0r opened this issue May 18, 2022 · 3 comments · Fixed by #2388

Comments

@klein0r
Copy link
Contributor

klein0r commented May 18, 2022

Situation:

  1. ioBroker is running on a system with redis
  2. redis is used for objects and states
  3. the system creates backups automatically (to a usb stick)
  4. the system crashed

Solution:

  1. Setting up a new iobroker installation with the installation script (curl -sLf https://iobroker.net/install.sh | bash -)
  2. Restoring the backup from the usb stick

Issue:

  1. The new iobroker installation has configured jsonl as database for objects and states
  2. The backup configuration contains redis as database

After the restore process, all information have been written to jsonl, the redis database is empty but iobroker uses the redis dabase instead of jsonl.

Tested with js-controller 4.0.21


Expected result:

The restore process recognizes, that the backup target is redis and uses that configuration of the backup before restoring the databases

or

The restore process keeps the database configuration of the current (new) installation, restores the database to that target and overrides the database configuration of the restored config (in this case from redis to jsonl). When the user wants to use redis afterwards, the iob setup custom process is required to migrate the data.

@klein0r
Copy link
Contributor Author

klein0r commented May 18, 2022

In my opinion option 2 would be the better way

  1. The js-controller can save the objects and states attribute of /opt/iobroker/iobroker-data/iobroker.json before the restore process (of the current system)
  2. The backup will be restored
  3. The js-controller overrides these properties to ensure everything is working again
  4. If the config is different, the user should be informed with a warning (e.g. backup has configured redis as database, but the current system uses jsonl)
"objects": {
  "type": "redis",
  "typeComment": "Possible values: 'file' - [port 9001], redis - [port 6379], couch - [port 5984].",
  "host": "127.0.0.1",
  "port": 6379,
  "noFileCache": false,
  "maxQueue": 1000,
  "connectTimeout": 2000,
  "writeFileInterval": 5000,
  "options": {
    "auth_pass": null,
    "retry_max_delay": 5000,
    "retry_max_count": 19,
    "db": 0,
    "family": 0
  },
  "backup": {
    "disabled": false,
    "files": 24,
    "filesComment": "Minimal number of backup files, after the deletion will be executed according to backupTime settings",
    "hours": 48,
    "hoursComment": "All backups older than 48 hours will be deleted. But only if the number of files is greater than of backupNumber",
    "period": 120,
    "periodComment": "by default backup every 2 hours. Time is in minutes. To disable backup set the value to 0",
    "path": "",
    "pathComment": "Absolute path to backup directory or empty to backup in data directory"
  }
},
"states": {
  "type": "redis",
  "typeComment": "Possible values: 'file' - [port 9000], 'redis' - [port 6379].",
  "host": "127.0.0.1",
  "port": 6379,
  "connectTimeout": 2000,
  "writeFileInterval": 30000,
  "options": {
    "auth_pass": null,
    "retry_max_delay": 5000,
    "retry_max_count": 19,
    "db": 0,
    "family": 0
  },
  "backup": {
    "disabled": false,
    "files": 24,
    "filesComment": "Minimal number of backup files, after the deletion will be executed according to backupTime settings",
    "hours": 48,
    "hoursComment": "All backups older than 48 hours will be deleted. But only if the number of files is greater than of backupNumber",
    "period": 120,
    "periodComment": "by default backup every 2 hours. Time is in minutes. To disable backup set the value to 0",
    "path": "",
    "pathComment": "Absolute path to backup directory or empty to backup in data directory"
  }
},

@klein0r
Copy link
Contributor Author

klein0r commented Jul 27, 2023

I couldn't find some code where the iobroker.json is modified before the restore. Looks like everything is used 1:1 of the backup file:

await this.cleanDatabase(false);
console.log(`host.${hostname} done.`);
// upload all data into DB
// restore ioBroker.json
if (restore.config) {
fs.writeFileSync(tools.getConfigFileName(), JSON.stringify(restore.config, null, 2));
}

A third option:

  • Check if the current configured database target of objects and states matches the backup
  • Stop the backup process if the values differ (maybe in _ensureCompatibility)

private _ensureCompatibility(
controllerDir: string,
backupHostname: string,
backupObjects: BackupObject[],
force: boolean
): void | number {

@foxriver76 I don't know how to setup a dev system of the js-controller, so it is not that easy to contribute here.

@foxriver76
Copy link
Collaborator

If it’s important I can put it on my list. And yes dev server for controller still planned 😬

#2161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants