mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	cleanup of old backup files
This commit is contained in:
		
							parent
							
								
									ee4eca33d4
								
							
						
					
					
						commit
						b7a5dca803
					
				
							
								
								
									
										4
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								TODO
									
									
									
									
									
								
							@ -6,6 +6,10 @@ New features:
 | 
			
		||||
    deterministic to allow lookup by cipher text
 | 
			
		||||
- db upgrade / migration
 | 
			
		||||
- db backup into directory
 | 
			
		||||
  - basic impl done
 | 
			
		||||
  - configurable backup time interval
 | 
			
		||||
  - delete old backups
 | 
			
		||||
  - configurable backup deletion
 | 
			
		||||
- might do the same thing with alt-j and alt-l
 | 
			
		||||
- ctrl-b nad linkem by mohlo byt goto do notu
 | 
			
		||||
- potencialne nova navigace back - forward
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,11 @@
 | 
			
		||||
from datetime import datetime
 | 
			
		||||
 | 
			
		||||
import utils
 | 
			
		||||
from sql import getOption, setOption
 | 
			
		||||
from sql import getOption, setOption, commit
 | 
			
		||||
import config_provider
 | 
			
		||||
from shutil import copyfile
 | 
			
		||||
import os
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
def backup():
 | 
			
		||||
    now = utils.nowTimestamp()
 | 
			
		||||
@ -20,3 +22,25 @@ def backup():
 | 
			
		||||
        copyfile(document_path, backup_directory + "/" + "backup-" + date_str + ".db")
 | 
			
		||||
 | 
			
		||||
        setOption('last_backup_date', now)
 | 
			
		||||
        commit()
 | 
			
		||||
 | 
			
		||||
        cleanup_old_backups()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def cleanup_old_backups():
 | 
			
		||||
    now = datetime.utcnow()
 | 
			
		||||
    config = config_provider.getConfig()
 | 
			
		||||
    backup_directory = config['Backup']['backupDirectory']
 | 
			
		||||
 | 
			
		||||
    for file in os.listdir(backup_directory):
 | 
			
		||||
        match = re.search(r"backup-([0-9 -:]+)\.db", file)
 | 
			
		||||
 | 
			
		||||
        if match:
 | 
			
		||||
            date_str = match.group(1)
 | 
			
		||||
 | 
			
		||||
            date = datetime.strptime(date_str, "%Y-%m-%d %H:%M")
 | 
			
		||||
 | 
			
		||||
            if (now - date).days > 30:
 | 
			
		||||
                print("Removing old backup - " + file)
 | 
			
		||||
 | 
			
		||||
                os.remove(backup_directory + "/" + file)
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user