<commit_before>
function BackupRestore(options) {
    var fs = require('fs');
    var tools = require(__dirname + '/tools.js');

    // allow use without new operator
    if (!(this instanceof BackupRestore)) return new BackupRestore(options);

    var that = this;

    var options = options || {};

    if (!options.states)      throw "Invalid arguments: states is missing";
    if (!options.objects)     throw "Invalid arguments: objects is missing";
    if (!options.processExit) throw "Invalid arguments: processExit is missing";

    var objects           = options.objects;
    var states            = options.states;
    var processExit       = options.processExit;
    var uploadAdapter     = options.uploadAdapter;
    var cleanDatabase     = options.cleanDatabase;
    var restartController = options.restartController;
    var mime;

    // --------------------------------------- BACKUP ---------------------------------------------------
    function _copyFile(id, srcPath, destPath, callback) {
        objects.readFile(id, srcPath, "", function (err, data) {
            if (data) fs.writeFileSync(destPath, data);
            callback();
        });
    }

    function copyDir(id, srcPath, destPath, callback) {
        var count = 0;
        if (!fs.existsSync(destPath)) fs.mkdirSync(destPath);
        objects.readDir(id, srcPath, function (err, res) {
            if (res) {
                for (var t = 0; t < res.length; t++) {
                    if (res[t].isDir) {
                        count++;
                        copyDir(id, srcPath + '/' + res[t].file, destPath + '/' + res[t].file, function () {
                            count--;
                            if (!count) callback();
                        });
                    } else {
                        if (!fs.existsSync(destPath)) fs.mkdirSync(destPath);
                        count++;
                        _copyFile(id, srcPath + '/' + res[t].file, destPath + '/' + res[t].file, function () {
                            count--;
                            if (!count) callback();
                        });
                    }
                }
            }
            if (!count) callback();
        });
    }

    function getBackupDir() {
        var dataDir = tools.getDefaultDataDir();

        // All pathes are returned always relative to /node_modules/iobroker.js-controller
        if (dataDir) {
            if (dataDir[0] == '.' && dataDir[1] == '.') {
                dataDir = __dirname + '/../' + dataDir;
            } else if (dataDir[0] == '.' && dataDir[1] == '/') {
                dataDir = __dirname + '/../' + dataDir.substring(2);
            }
        }
        dataDir = dataDir.replace(/\\/g, '/');
        if (dataDir[dataDir.length - 1] != '/') dataDir += '/';

        var parts = dataDir.split('/');
        parts.pop();// remove data or iobroker-data
        parts.pop();

        return parts.join('/') + '/backups/';
    }

    this.createBackup = function (name, callback) {
        var count = 0;

        if (!name) {
            var d = new Date();
            name = d.getFullYear() + '_' +
                ('0' + d.getMonth()).slice(-2) + '_' +
                ('0' + d.getDate()).slice(-2) + '-' +
                ('0' + d.getHours()).slice(-2) + '_' +<commit_msg>(bluefox) fix backup month<commit_after>
function BackupRestore(options) {
    var fs = require('fs');
    var tools = require(__dirname + '/tools.js');

    // allow use without new operator
    if (!(this instanceof BackupRestore)) return new BackupRestore(options);

    var that = this;

    var options = options || {};

    if (!options.states)      throw "Invalid arguments: states is missing";
    if (!options.objects)     throw "Invalid arguments: objects is missing";
    if (!options.processExit) throw "Invalid arguments: processExit is missing";

    var objects           = options.objects;
    var states            = options.states;
    var processExit       = options.processExit;
    var uploadAdapter     = options.uploadAdapter;
    var cleanDatabase     = options.cleanDatabase;
    var restartController = options.restartController;
    var mime;

    // --------------------------------------- BACKUP ---------------------------------------------------
    function _copyFile(id, srcPath, destPath, callback) {
        objects.readFile(id, srcPath, "", function (err, data) {
            if (data) fs.writeFileSync(destPath, data);
            callback();
        });
    }

    function copyDir(id, srcPath, destPath, callback) {
        var count = 0;
        if (!fs.existsSync(destPath)) fs.mkdirSync(destPath);
        objects.readDir(id, srcPath, function (err, res) {
            if (res) {
                for (var t = 0; t < res.length; t++) {
                    if (res[t].isDir) {
                        count++;
                        copyDir(id, srcPath + '/' + res[t].file, destPath + '/' + res[t].file, function () {
                            count--;
                            if (!count) callback();
                        });
                    } else {
                        if (!fs.existsSync(destPath)) fs.mkdirSync(destPath);
                        count++;
                        _copyFile(id, srcPath + '/' + res[t].file, destPath + '/' + res[t].file, function () {
                            count--;
                            if (!count) callback();
                        });
                    }
                }
            }
            if (!count) callback();
        });
    }

    function getBackupDir() {
        var dataDir = tools.getDefaultDataDir();

        // All pathes are returned always relative to /node_modules/iobroker.js-controller
        if (dataDir) {
            if (dataDir[0] == '.' && dataDir[1] == '.') {
                dataDir = __dirname + '/../' + dataDir;
            } else if (dataDir[0] == '.' && dataDir[1] == '/') {
                dataDir = __dirname + '/../' + dataDir.substring(2);
            }
        }
        dataDir = dataDir.replace(/\\/g, '/');
        if (dataDir[dataDir.length - 1] != '/') dataDir += '/';

        var parts = dataDir.split('/');
        parts.pop();// remove data or iobroker-data
        parts.pop();

        return parts.join('/') + '/backups/';
    }

    this.createBackup = function (name, callback) {
        var count = 0;

        if (!name) {
            var d = new Date();
            name = d.getFullYear() + '_' +
                ('0' + (d.getMonth() + 1)).slice(-2) + '_' +
                ('0' + d.getDate()).slice(-2) + '-' +
                ('0' + d.getHours()).slice(-2) + '_' +
{'fraction_non_alphanumeric': 0.17104670370926567, 'fraction_numerical': 0.004655353656705211, 'mean_word_length': 1.4218181818181819, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1400773', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1773, 'n_words': 426}