Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This requires Node.js to run. Please put this in a file and run "node filename"
- //It was created to merge old backups of anope.db-date files located in the same directory as this script.
- //It will go from the last back up to the earliest.
- 'use strict'
- //BACKUP ALL CURRENT DATABASE FILES BEFORE REPLACING WITH THE OUTPUT OF THIS SCRIPT!
- //Made by Colten Covington / Colten45
- //You may contact me via colten.covington@gmail.com or colten at tmro.tv if you need help
- //or come to any chat related to TMRO.tv and I am usually around those.
- //Set each type to false or true depending on what you want to merge.
- //All set to true with seeninfoMergeALL set to false is a full merge.
- let types = {
- 'BotInfo': true,
- 'Stats': true,
- 'NickCore': true,
- 'NickAlias': true,
- 'ChannelInfo': true,
- 'ChanAccess': true,
- 'ModeLock': true,
- 'SeenInfo': true,
- 'AJoinEntry': true,
- 'NSMiscData': true,
- 'Exception': true
- }
- //seeninfoMergeALL set to false will only merge seeninfo of users who are registered and on the very first db file.
- //seeninfoMergeALL set to true will merge all seeninfo WARNING this can be quite big if done on a large set of database backups.
- let seeninfoMergeALL = false;
- //Only known thing to me currently is stats are duplicated due to below code using the last param of the first DATA line for an OBJECT
- //I had one bug in an old db that was a NSMiscDataUSERNAME OBJECT So the types object above is checked to make sure corrupted data is not brought over.
- const path = require('path');
- const fs = require('fs');
- const directoryPath = path.join(__dirname);
- let objects = [];
- let objectnames = {};
- let objectnamescaseins = {};
- let dontadd = [];
- let nickcore = '';
- let i = 0;
- let stats = true;
- fs.readdir(directoryPath, function (err, files) {
- if (err) {
- return console.log('Unable to scan directory: ' + err);
- }
- files = files.reverse()
- files.forEach(function (file) {
- if (file.indexOf('anope') == 0) {
- i++;
- var contents = fs.readFileSync(file, 'utf8');
- let blam = contents.trim().split('END').slice(0,-1);
- blam.forEach(function (object) {
- objects.push(object);
- object = object.trim().split('\n').splice(0,object.trim().split('\n').length);
- let data = object.splice(1);
- if (data.length != 0 && types[object[0].split(' ')[1]]) {
- if (object[0].split(' ')[1] == 'Stats' && stats) {
- if (!objectnames[object[0].split(' ')[1]]) {
- objectnames[object[0].split(' ')[1]] = {objectCount:0};
- objectnamescaseins[object[0].split(' ')[1]] = {objectCount:0};
- }
- if (!objectnamescaseins[object[0].split(' ')[1]][(['ChanAccess','ModeLock'].indexOf(object[0].split(' ')[1]) != -1) ? data[2].split(' ')[data[2].split(' ').length - 1].toLowerCase() : data[0].split(' ')[data[0].split(' ').length - 1].toLowerCase()] && dontadd.indexOf(data[0].split(' ')[data[0].split(' ').length - 1]) == -1) {
- objectnames[object[0].split(' ')[1]][(['ChanAccess','ModeLock'].indexOf(object[0].split(' ')[1]) != -1) ? data[2].split(' ')[data[2].split(' ').length - 1] : data[0].split(' ')[data[0].split(' ').length - 1]] = {firstFile:i};
- objectnamescaseins[object[0].split(' ')[1]][(['ChanAccess','ModeLock'].indexOf(object[0].split(' ')[1]) != -1) ? data[2].split(' ')[data[2].split(' ').length - 1].toLowerCase() : data[0].split(' ')[data[0].split(' ').length - 1].toLowerCase()] = {};
- data.forEach(function (d) {
- let type = objectnames[object[0].split(' ')[1]][(['ChanAccess','ModeLock'].indexOf(object[0].split(' ')[1]) != -1) ? data[2].split(' ')[data[2].split(' ').length - 1] : data[0].split(' ')[data[0].split(' ').length - 1]];
- type[d.split(' ')[1]] = d.split(' ').slice(2)[0] == '' ? d.split(' ').slice(2).join(' '): d.split(' ').slice(2).join(' ');
- })
- }
- objectnames[object[0].split(' ')[1]].objectCount++;
- stats = false;
- }
- else if (object[0].split(' ')[1] != 'Stats') {
- if (!objectnames[object[0].split(' ')[1]]) {
- objectnames[object[0].split(' ')[1]] = {objectCount:0};
- objectnamescaseins[object[0].split(' ')[1]] = {objectCount:0};
- }
- if (!objectnamescaseins[object[0].split(' ')[1]][(['ChanAccess','ModeLock'].indexOf(object[0].split(' ')[1]) != -1) ? data[2].split(' ')[data[2].split(' ').length - 1].toLowerCase() : data[0].split(' ')[data[0].split(' ').length - 1].toLowerCase()] && dontadd.indexOf(data[0].split(' ')[data[0].split(' ').length - 1]) == -1) {
- objectnames[object[0].split(' ')[1]][(['ChanAccess','ModeLock'].indexOf(object[0].split(' ')[1]) != -1) ? data[2].split(' ')[data[2].split(' ').length - 1] : data[0].split(' ')[data[0].split(' ').length - 1]] = {firstFile:i};
- objectnamescaseins[object[0].split(' ')[1]][(['ChanAccess','ModeLock'].indexOf(object[0].split(' ')[1]) != -1) ? data[2].split(' ')[data[2].split(' ').length - 1].toLowerCase() : data[0].split(' ')[data[0].split(' ').length - 1].toLowerCase()] = {};
- data.forEach(function (d) {
- let type = objectnames[object[0].split(' ')[1]][(['ChanAccess','ModeLock'].indexOf(object[0].split(' ')[1]) != -1) ? data[2].split(' ')[data[2].split(' ').length - 1] : data[0].split(' ')[data[0].split(' ').length - 1]];
- type[d.split(' ')[1]] = d.split(' ').slice(2)[0] == '' ? d.split(' ').slice(2).join(' '): d.split(' ').slice(2).join(' ');
- })
- }
- objectnames[object[0].split(' ')[1]].objectCount++;
- }
- }
- })
- }
- });
- for (var objectType in objectnames) {
- if (types[objectType]) {
- for (var property in objectnames[objectType]) {
- if (objectnames[objectType].hasOwnProperty(property) && property != "objectCount") {
- if (!seeninfoMergeALL && objectType == 'SeenInfo') {
- if (objectnames.NickCore[property] || objectnames[objectType][property].firstFile == 1) {
- nickcore += 'OBJECT ' + objectType + '\u000a';
- let datatype = '';
- for (var type in objectnames[objectType][property]) {
- if (objectnames[objectType].hasOwnProperty(property) && type != "firstFile") {
- datatype += 'DATA ' + type + ' ' + objectnames[objectType][property][type] + '\u000a';
- }
- }
- nickcore += datatype;
- nickcore += 'END\u000a';
- }
- }
- else {
- nickcore += 'OBJECT ' + objectType + '\u000a';
- let datatype = '';
- for (var type in objectnames[objectType][property]) {
- if (objectnames[objectType].hasOwnProperty(property) && type != "firstFile") {
- datatype += 'DATA ' + type + ' ' + objectnames[objectType][property][type] + '\u000a';
- }
- }
- nickcore += datatype;
- nickcore += 'END\u000a';
- }
- }
- }
- }
- }
- fs.writeFileSync('new.db', nickcore);
- console.log('Done')
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement