iobroker.backitup
Version:
ioBroker.backitup allows you to backup and restore your ioBroker installation and other systems, such as databases, Zigbee, scripts and many more.
62 lines (53 loc) • 2.16 kB
JavaScript
;
const fs = require('node:fs');
const getDate = require('../tools').getDate;
const path = require('node:path');
function command(options, log, callback) {
let zigbeeInst = [];
const compress = require('../targz').compress;
for (let i = 0; i <= 5; i++) {
let pth = path.join(options.path, `zigbee_${i}`);
if (fs.existsSync(pth)) {
let nameSuffix;
if (options.hostType === 'Slave') {
nameSuffix = options.slaveSuffix ? options.slaveSuffix : '';
} else {
nameSuffix = options.nameSuffix ? options.nameSuffix : '';
}
const fileName = path.join(options.backupDir, `zigbee.${i}_${getDate()}${nameSuffix ? `_${nameSuffix}` : ''}_backupiobroker.tar.gz`);
options.context.fileNames.push(fileName);
compress({
src: pth,
dest: fileName,
tar: {
ignore: function (name) {
return path.extname(name) === '.gz' // ignore .tar.gz files when packing
}
}
}, (err, stdout, stderr) => {
if (err) {
options.context.errors.zigbee = err.toString();
stderr && log.error(stderr);
if (callback) {
callback(err, stderr);
callback = null;
}
} else {
options.context.types.push(`zigbee.${i}`);
options.context.done.push(`zigbee.${i}`);
}
});
zigbeeInst.push(`zigbee.${i}`);
if (i === 5) {
zigbeeInst.length ? log.debug(`found zigbee database: ${zigbeeInst}`) : log.warn('no zigbee database found!!');
}
} else if (!fs.existsSync(pth) && i === 5) {
zigbeeInst.length ? log.debug(`found zigbee database: ${zigbeeInst}`) : log.warn('no zigbee database found!!');
callback && callback(null, 'done');
}
}
}
module.exports = {
command,
ignoreErrors: true
};