mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
more logging
This commit is contained in:
parent
b4bb1b539e
commit
8e47e34d1f
@ -27,7 +27,7 @@ router.put('/:noteId/moveTo/:parentId', auth.checkApiAuth, async (req, res, next
|
||||
await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?",
|
||||
[parentId, newNotePos, now, noteId]);
|
||||
|
||||
await sql.addAudit(audit_category.CHANGE_PARENT, req, noteId);
|
||||
await sql.addAudit(audit_category.CHANGE_PARENT, req, noteId, null, parentId);
|
||||
|
||||
await sql.commit();
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
const utils = require('./utils');
|
||||
const sql = require('./sql');
|
||||
const config = require('./config');
|
||||
const fs = require('fs-extra');
|
||||
const dataDir = require('./data_dir');
|
||||
const log = require('./log');
|
||||
|
||||
async function regularBackup() {
|
||||
const now = utils.nowTimestamp();
|
||||
@ -20,18 +20,19 @@ async function regularBackup() {
|
||||
async function backupNow() {
|
||||
const now = utils.nowTimestamp();
|
||||
|
||||
const backup_directory = config.Backup.backupDirectory;
|
||||
|
||||
const date_str = new Date().toISOString().substr(0, 19);
|
||||
|
||||
if (!fs.existsSync(dataDir.BACKUP_DIR)) {
|
||||
fs.mkdirSync(dataDir.BACKUP_DIR, 0o700);
|
||||
}
|
||||
|
||||
fs.copySync(dataDir.DOCUMENT_PATH, dataDir.BACKUP_DIR + "/" + "backup-" + date_str + ".db");
|
||||
const backupFile = dataDir.BACKUP_DIR + "/" + "backup-" + date_str + ".db";
|
||||
|
||||
fs.copySync(dataDir.DOCUMENT_PATH, backupFile);
|
||||
|
||||
log.info("Created backup at " + backupFile);
|
||||
|
||||
await sql.setOption('last_backup_date', now);
|
||||
//await sql.commit();
|
||||
}
|
||||
|
||||
async function cleanupOldBackups() {
|
||||
@ -46,7 +47,7 @@ async function cleanupOldBackups() {
|
||||
const date = Date.parse(date_str);
|
||||
|
||||
if (now.getTime() - date.getTime() > 30 * 24 * 3600 * 1000) {
|
||||
console.log("Removing old backup - " + file);
|
||||
log.info("Removing old backup - " + file);
|
||||
|
||||
fs.unlink(dataDir.BACKUP_DIR + "/" + file);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
const backup = require('./backup');
|
||||
const sql = require('./sql');
|
||||
const fs = require('fs-extra');
|
||||
const log = require('./log');
|
||||
|
||||
const APP_DB_VERSION = 9;
|
||||
const MIGRATIONS_DIR = "./migrations";
|
||||
@ -8,6 +9,7 @@ const MIGRATIONS_DIR = "./migrations";
|
||||
async function migrate() {
|
||||
const migrations = [];
|
||||
|
||||
// backup before attempting migration
|
||||
await backup.backupNow();
|
||||
|
||||
const currentDbVersion = parseInt(await sql.getOption('db_version'));
|
||||
@ -38,7 +40,7 @@ async function migrate() {
|
||||
const migrationSql = fs.readFileSync(MIGRATIONS_DIR + "/" + mig.file).toString('utf8');
|
||||
|
||||
try {
|
||||
console.log("Running script: ", migrationSql);
|
||||
log.info("Attempting migration to version " + mig.dbVersion + " with script: " + migrationSql);
|
||||
|
||||
await sql.beginTransaction();
|
||||
|
||||
@ -48,17 +50,20 @@ async function migrate() {
|
||||
|
||||
await sql.commit();
|
||||
|
||||
log.info("Migration to version " + mig.dbVersion + " has been successful.");
|
||||
|
||||
mig['success'] = true;
|
||||
}
|
||||
catch (e) {
|
||||
mig['success'] = false;
|
||||
mig['error'] = e.stack;
|
||||
|
||||
console.log("error during migration: ", e);
|
||||
log.error("error during migration to version " + mig.dbVersion + ": " + e.stack);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return migrations;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
const fs = require('fs');
|
||||
const crypto = require('crypto');
|
||||
const dataDir = require('./data_dir');
|
||||
const log = require('./log');
|
||||
|
||||
const sessionSecretPath = dataDir.TRILIUM_DATA_DIR + "/session_secret.txt";
|
||||
|
||||
@ -17,6 +18,8 @@ function randomValueHex(len) {
|
||||
if (!fs.existsSync(sessionSecretPath)) {
|
||||
sessionSecret = randomValueHex(64);
|
||||
|
||||
log.info("Generated session secret");
|
||||
|
||||
fs.writeFileSync(sessionSecretPath, sessionSecret, 'ASCII');
|
||||
}
|
||||
else {
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
const db = require('sqlite');
|
||||
const utils = require('./utils');
|
||||
const log = require('./log');
|
||||
|
||||
async function insert(table_name, rec) {
|
||||
const columns = Object.keys(rec).join(", ");
|
||||
@ -55,6 +56,9 @@ async function addAudit(category, req=null, noteId=null, changeFrom=null, change
|
||||
|
||||
const browserId = req == null ? null : req.get('x-browser-id');
|
||||
|
||||
log.info("audit: " + category + ", browserId=" + browserId + ", noteId=" + noteId + ", from=" + changeFrom
|
||||
+ ", to=" + changeTo + ", comment=" + comment);
|
||||
|
||||
await execute("INSERT INTO audit_log (date_modified, category, browser_id, note_id, change_from, change_to, comment)"
|
||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?)", [now, category, browserId, noteId, changeFrom, changeTo, comment]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user