Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
basic backup implementation (in progress)
azivneree4eca33d402
diff --git a/TODO b/TODOindex 8f60bd71f8..fdab149661 100644--- a/TODO+++ b/TODO@@ -12,6 +12,7 @@ New features:- javascript editor- persisted recent notes (is wiped out after reload)- sync of current page?+- create new subnote from inside the editor - possibly with selection of textRefactorings:- modularize frontenddiff --git a/src/backup.py b/src/backup.pynew file mode 100644index 0000000000..7ac14c31dd--- /dev/null+++ b/src/backup.py@@ -0,0 +1,22 @@+from datetime import datetime++import utils+from sql import getOption, setOption+import config_provider+from shutil import copyfile++def backup():+ now = utils.nowTimestamp()+ last_backup_date = int(getOption('last_backup_date'))++ if now - last_backup_date > 43200:+ config = config_provider.getConfig()++ document_path = config['Document']['documentPath']+ backup_directory = config['Backup']['backupDirectory']++ date_str = datetime.utcnow().strftime("%Y-%m-%d %H:%M")++ copyfile(document_path, backup_directory + "/" + "backup-" + date_str + ".db")++ setOption('last_backup_date', now)\ No newline at end of filediff --git a/src/tree_api.py b/src/tree_api.pyindex 44509c37a8..6368b9e2bf 100644--- a/src/tree_api.py+++ b/src/tree_api.py@@ -1,19 +1,20 @@import base64import os-import math-import timefrom flask import Blueprint, jsonifyfrom flask_login import login_requiredfrom sql import getResults, getSingleResult, getOptionimport utils+import backuptree_api = Blueprint('tree_api', __name__)@tree_api.route('/api/tree', methods = ['GET'])@login_requireddef getTree():+ backup.backup()+notes = getResults("select ""notes_tree.*, ""COALESCE(clone.note_title, notes.note_title) as note_title, "diff --git a/src/utils.py b/src/utils.pyindex 3bbdf40e1e..31e7dcbb4c 100644--- a/src/utils.py+++ b/src/utils.py@@ -2,4 +2,4 @@ from datetime import datetimeimport timedef nowTimestamp():- return time.mktime(datetime.utcnow().timetuple())+ return int(time.mktime(datetime.utcnow().timetuple()))