mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 01:36:24 +01:00 
			
		
		
		
	added option to disable backup, #2210
This commit is contained in:
		| @@ -11,13 +11,14 @@ export async function showDialog() { | ||||
|     utils.openDialog($dialog); | ||||
|  | ||||
|     (await Promise.all([ | ||||
|         import('./options/advanced.js'), | ||||
|         import('./options/appearance.js'), | ||||
|         import('./options/shortcuts.js'), | ||||
|         import('./options/code_notes.js'), | ||||
|         import('./options/credentials.js'), | ||||
|         import('./options/other.js'), | ||||
|         import('./options/backup.js'), | ||||
|         import('./options/sync.js'), | ||||
|         import('./options/keyboard_shortcuts.js'), | ||||
|         import('./options/other.js'), | ||||
|         import('./options/advanced.js') | ||||
|     ])) | ||||
|         .map(m => new m.default) | ||||
|         .forEach(tab => { | ||||
|   | ||||
| @@ -24,12 +24,6 @@ const TPL = ` | ||||
|  | ||||
| <button id="anonymize-button" class="btn">Save anonymized database</button><br/><br/> | ||||
|  | ||||
| <h4>Backup database</h4> | ||||
|  | ||||
| <p>Trilium has automatic backup (daily, weekly, monthly), but you can also trigger a manual backup here.</p> | ||||
|  | ||||
| <button id="backup-database-button" class="btn">Backup database now</button><br/><br/> | ||||
|  | ||||
| <h4>Vacuum database</h4> | ||||
|  | ||||
| <p>This will rebuild the database which will typically result in a smaller database file. No data will be actually changed.</p> | ||||
| @@ -70,12 +64,6 @@ export default class AdvancedOptions { | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         this.$backupDatabaseButton.on('click', async () => { | ||||
|             const {backupFile} = await server.post('database/backup-database'); | ||||
|  | ||||
|             toastService.showMessage("Database has been backed up to " + backupFile, 10000); | ||||
|         }); | ||||
|  | ||||
|         this.$vacuumDatabaseButton.on('click', async () => { | ||||
|             await server.post('database/vacuum-database'); | ||||
|  | ||||
|   | ||||
							
								
								
									
										78
									
								
								src/public/app/dialogs/options/backup.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								src/public/app/dialogs/options/backup.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,78 @@ | ||||
| import server from "../../services/server.js"; | ||||
| import toastService from "../../services/toast.js"; | ||||
|  | ||||
| const TPL = ` | ||||
| <h4>Automatic backup</h4> | ||||
|  | ||||
| <p>Trilium can back up the database automatically:</p> | ||||
|  | ||||
| <div class="custom-control custom-checkbox"> | ||||
|     <input type="checkbox" class="custom-control-input" id="daily-backup-enabled"> | ||||
|     <label class="custom-control-label" for="daily-backup-enabled">Enable daily backup</label> | ||||
| </div> | ||||
|  | ||||
| <div class="custom-control custom-checkbox"> | ||||
|     <input type="checkbox" class="custom-control-input" id="weekly-backup-enabled"> | ||||
|     <label class="custom-control-label" for="weekly-backup-enabled">Enable weekly backup</label> | ||||
| </div> | ||||
|  | ||||
| <div class="custom-control custom-checkbox"> | ||||
|     <input type="checkbox" class="custom-control-input" id="monthly-backup-enabled"> | ||||
|     <label class="custom-control-label" for="monthly-backup-enabled">Enable monthly backup</label> | ||||
| </div> | ||||
|  | ||||
| <br/> | ||||
|  | ||||
| <p>It's recommended to keep the backup turned on, but this can make application startup slow with large databases and/or slow storage devices.</p> | ||||
|  | ||||
| <br/> | ||||
|  | ||||
| <h4>Backup now</h4> | ||||
|  | ||||
| <button id="backup-database-button" class="btn">Backup database now</button><br/><br/> | ||||
| `; | ||||
|  | ||||
| export default class BackupOptions { | ||||
|     constructor() { | ||||
|         $("#options-backup").html(TPL); | ||||
|  | ||||
|         this.$backupDatabaseButton = $("#backup-database-button"); | ||||
|  | ||||
|         this.$backupDatabaseButton.on('click', async () => { | ||||
|             const {backupFile} = await server.post('database/backup-database'); | ||||
|  | ||||
|             toastService.showMessage("Database has been backed up to " + backupFile, 10000); | ||||
|         }); | ||||
|  | ||||
|         this.$dailyBackupEnabled = $("#daily-backup-enabled"); | ||||
|         this.$weeklyBackupEnabled = $("#weekly-backup-enabled"); | ||||
|         this.$monthlyBackupEnabled = $("#monthly-backup-enabled"); | ||||
|  | ||||
|         this.$dailyBackupEnabled.on('change', () => { | ||||
|             const opts = { 'dailyBackupEnabled': this.$dailyBackupEnabled.is(":checked") ? "true" : "false" }; | ||||
|             server.put('options', opts).then(() => toastService.showMessage("Options change have been saved.")); | ||||
|  | ||||
|             return false; | ||||
|         }); | ||||
|  | ||||
|         this.$weeklyBackupEnabled.on('change', () => { | ||||
|             const opts = { 'weeklyBackupEnabled': this.$weeklyBackupEnabled.is(":checked") ? "true" : "false" }; | ||||
|             server.put('options', opts).then(() => toastService.showMessage("Options change have been saved.")); | ||||
|  | ||||
|             return false; | ||||
|         }); | ||||
|  | ||||
|         this.$monthlyBackupEnabled.on('change', () => { | ||||
|             const opts = { 'monthlyBackupEnabled': this.$monthlyBackupEnabled.is(":checked") ? "true" : "false" }; | ||||
|             server.put('options', opts).then(() => toastService.showMessage("Options change have been saved.")); | ||||
|  | ||||
|             return false; | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     optionsLoaded(options) { | ||||
|         this.$dailyBackupEnabled.prop("checked", options['dailyBackupEnabled'] === 'true'); | ||||
|         this.$weeklyBackupEnabled.prop("checked", options['weeklyBackupEnabled'] === 'true'); | ||||
|         this.$monthlyBackupEnabled.prop("checked", options['monthlyBackupEnabled'] === 'true'); | ||||
|     } | ||||
| } | ||||
| @@ -35,7 +35,7 @@ let globActions; | ||||
| 
 | ||||
| export default class KeyboardShortcutsOptions { | ||||
|     constructor() { | ||||
|         $("#options-keyboard-shortcuts").html(TPL); | ||||
|         $("#options-shortcuts").html(TPL); | ||||
| 
 | ||||
|         $("#options-keyboard-shortcuts-reload-app").on("click", () => utils.reloadFrontendApp()); | ||||
| 
 | ||||
| @@ -50,7 +50,10 @@ const ALLOWED_OPTIONS = new Set([ | ||||
|     'autoCollapseNoteTree', | ||||
|     'autoReadonlySizeText', | ||||
|     'autoReadonlySizeCode', | ||||
|     'overrideThemeFonts' | ||||
|     'overrideThemeFonts', | ||||
|     'dailyBackupEnabled', | ||||
|     'weeklyBackupEnabled', | ||||
|     'monthlyBackupEnabled', | ||||
| ]); | ||||
|  | ||||
| function getOptions() { | ||||
|   | ||||
| @@ -20,12 +20,22 @@ function regularBackup() { | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function periodBackup(optionName, fileName, periodInSeconds) { | ||||
|     const now = new Date(); | ||||
|     const lastDailyBackupDate = dateUtils.parseDateTime(optionService.getOption(optionName)); | ||||
| function isBackupEnabled(backupType) { | ||||
|     const optionName = `${backupType}BackupEnabled`; | ||||
|  | ||||
|     if (now.getTime() - lastDailyBackupDate.getTime() > periodInSeconds * 1000) { | ||||
|         backupNow(fileName); | ||||
|     return optionService.getOptionBool(optionName); | ||||
| } | ||||
|  | ||||
| function periodBackup(optionName, backupType, periodInSeconds) { | ||||
|     if (!isBackupEnabled(backupType)) { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     const now = new Date(); | ||||
|     const lastBackupDate = dateUtils.parseDateTime(optionService.getOption(optionName)); | ||||
|  | ||||
|     if (now.getTime() - lastBackupDate.getTime() > periodInSeconds * 1000) { | ||||
|         backupNow(backupType); | ||||
|  | ||||
|         optionService.setOption(optionName, dateUtils.utcNowDateTime()); | ||||
|     } | ||||
|   | ||||
| @@ -87,6 +87,9 @@ const defaultOptions = [ | ||||
|     { name: 'autoCollapseNoteTree', value: 'true', isSynced: true }, | ||||
|     { name: 'autoReadonlySizeText', value: '10000', isSynced: false }, | ||||
|     { name: 'autoReadonlySizeCode', value: '30000', isSynced: false }, | ||||
|     { name: 'dailyBackupEnabled', value: 'true', isSynced: false }, | ||||
|     { name: 'weeklyBackupEnabled', value: 'true', isSynced: false }, | ||||
|     { name: 'monthlyBackupEnabled', value: 'true', isSynced: false } | ||||
| ]; | ||||
|  | ||||
| function initStartupOptions() { | ||||
|   | ||||
| @@ -14,7 +14,7 @@ | ||||
|                             <a class="nav-link active" data-toggle="tab" href="#options-appearance">Appearance</a> | ||||
|                         </li> | ||||
|                         <li class="nav-item"> | ||||
|                             <a class="nav-link" data-toggle="tab" href="#options-keyboard-shortcuts">Keyboard shortcuts</a> | ||||
|                             <a class="nav-link" data-toggle="tab" href="#options-shortcuts">Shortcuts</a> | ||||
|                         </li> | ||||
|                         <li class="nav-item"> | ||||
|                             <a class="nav-link" data-toggle="tab" href="#options-code-notes">Code notes</a> | ||||
| @@ -22,6 +22,9 @@ | ||||
|                         <li class="nav-item"> | ||||
|                             <a class="nav-link" data-toggle="tab" href="#options-credentials">Username & password</a> | ||||
|                         </li> | ||||
|                         <li class="nav-item"> | ||||
|                             <a class="nav-link" data-toggle="tab" href="#options-backup">Backup</a> | ||||
|                         </li> | ||||
|                         <li class="nav-item"> | ||||
|                             <a class="nav-link" data-toggle="tab" href="#options-sync-setup">Sync</a> | ||||
|                         </li> | ||||
| @@ -35,11 +38,12 @@ | ||||
|                     <br/> | ||||
|                     <div class="tab-content"> | ||||
|                         <div id="options-appearance" class="tab-pane active"></div> | ||||
|                         <div id="options-keyboard-shortcuts" class="tab-pane"></div> | ||||
|                         <div id="options-shortcuts" class="tab-pane"></div> | ||||
|                         <div id="options-code-notes" class="tab-pane"></div> | ||||
|                         <div id="options-credentials" class="tab-pane"></div> | ||||
|                         <div id="options-other" class="tab-pane"></div> | ||||
|                         <div id="options-backup" class="tab-pane"></div> | ||||
|                         <div id="options-sync-setup" class="tab-pane"></div> | ||||
|                         <div id="options-other" class="tab-pane"></div> | ||||
|                         <div id="options-advanced" class="tab-pane"></div> | ||||
|                     </div> | ||||
|                 </div> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user