Zefau / ioBroker.jarvis

jarvis - just another remarkable vis
https://forum.iobroker.net/topic/49776
Other
150 stars 38 forks source link

Backup jarvis #2433

Open Zefau opened 11 months ago

Zefau commented 11 months ago
const fs = require('fs');
const path = require('path');
const date = new Date();

/*
 * CONFIG
 */
const backupFolder = '/opt/iobroker/backups/jarvis';
const states = [
    'jarvis.0.devices',
    'jarvis.0.layout',
    'jarvis.0.css',
    'jarvis.0.widgets',
];

/*
 * Backup Function
 */
function backupJarvis(states, folder) {
    // create date for first level
    folder = folder + '/' + date.getFullYear() + '-' + ('0' + (date.getMonth() + 1)).substr(-2) + '-' + ('0' + date.getDate()).substr(-2);
    if (!fs.existsSync(folder)) {
        fs.mkdirSync(folder, { 'recursive': true });
    }

    // get states and write to file
    states.forEach(stateId => {
        // get value from state
        const val = getState(stateId).val;

        // write value to file
        fs.writeFile(path.join(folder, stateId + '.txt'), val.toString(), () => {});
    });
}

// Scheduler
schedule('0 3 * * *', () => backupJarvis(states, backupFolder));

// Run instantly
backupJarvis(states, backupFolder);

@mcuiobroker Könntest du das in deine Dokumentation übernehmen?

Mittels des obigen Skripts kann jarvis gesichert werden. Einfach das Skript im ioBroker.javascript einfügen und ggf. die states in Bezug auf die Instanzen anpassen. Das Skript ist für ein Linux-System. Für Windows muss der Pfad angepasst werden.

Das Skript erstellt jede Nacht um 3 Uhr einen Ordner mit dem Datum und die gesicherten States als Text-Datei. Der Inhalt kann dann im Falle eines Restore einfach zurückkopiert werden.

image

mcuiobroker commented 11 months ago

Mache ich morgen

mcuiobroker commented 11 months ago

erledigt

Zefau commented 11 months ago

Magst du noch den Link hier posten?

mcuiobroker commented 11 months ago

https://mcuiobroker.gitbook.io/jarvis-infos/jarvis-v3/besonderheiten-v3/backup-restore#backup-script-zefau