mirror of
https://github.com/borgbase/vorta
synced 2025-01-03 05:36:19 +00:00
Preserve last creation log per profile for scheduler. By @real-yfprojects (#1296)
This commit is contained in:
parent
f76aa5a5f4
commit
b650ed3eb6
1 changed files with 22 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
from peewee import Tuple, fn
|
||||||
from playhouse import signals
|
from playhouse import signals
|
||||||
|
|
||||||
from vorta.autostart import open_app_at_startup
|
from vorta.autostart import open_app_at_startup
|
||||||
|
@ -34,9 +35,27 @@ def init_db(con=None):
|
||||||
DB.create_tables([RepoModel, RepoPassword, BackupProfileModel, SourceFileModel, SettingsModel,
|
DB.create_tables([RepoModel, RepoPassword, BackupProfileModel, SourceFileModel, SettingsModel,
|
||||||
ArchiveModel, WifiSettingModel, EventLogModel, SchemaVersion])
|
ArchiveModel, WifiSettingModel, EventLogModel, SchemaVersion])
|
||||||
|
|
||||||
# Delete old log entries after 3 months.
|
# Delete old log entries after 6 months.
|
||||||
three_months_ago = datetime.now() - timedelta(days=180)
|
# The last `create` command of each profile must not be deleted
|
||||||
EventLogModel.delete().where(EventLogModel.start_time < three_months_ago)
|
# since the scheduler uses it to determine the last backup time.
|
||||||
|
last_backups_per_profile = (
|
||||||
|
EventLogModel.select(EventLogModel.profile,
|
||||||
|
fn.MAX(EventLogModel.start_time))
|
||||||
|
.where(EventLogModel.subcommand == 'create')
|
||||||
|
.group_by(EventLogModel.profile))
|
||||||
|
last_scheduled_backups_per_profile = (
|
||||||
|
EventLogModel.select(EventLogModel.profile,
|
||||||
|
fn.MAX(EventLogModel.start_time))
|
||||||
|
.where(EventLogModel.subcommand == 'create',
|
||||||
|
EventLogModel.category == 'scheduled')
|
||||||
|
.group_by(EventLogModel.profile))
|
||||||
|
|
||||||
|
three_months_ago = datetime.now() - timedelta(days=6 * 30)
|
||||||
|
entry = Tuple(EventLogModel.profile, EventLogModel.start_time)
|
||||||
|
EventLogModel.delete().where(
|
||||||
|
EventLogModel.start_time < three_months_ago,
|
||||||
|
entry.not_in(last_backups_per_profile),
|
||||||
|
entry.not_in(last_scheduled_backups_per_profile)).execute()
|
||||||
|
|
||||||
# Migrations
|
# Migrations
|
||||||
current_schema, created = SchemaVersion.get_or_create(id=1, defaults={'version': SCHEMA_VERSION})
|
current_schema, created = SchemaVersion.get_or_create(id=1, defaults={'version': SCHEMA_VERSION})
|
||||||
|
@ -57,7 +76,3 @@ def init_db(con=None):
|
||||||
s.group = setting['group']
|
s.group = setting['group']
|
||||||
|
|
||||||
s.save()
|
s.save()
|
||||||
|
|
||||||
# Delete old log entries after 3 months.
|
|
||||||
three_months_ago = datetime.now() - timedelta(days=3)
|
|
||||||
EventLogModel.delete().where(EventLogModel.start_time < three_months_ago).execute()
|
|
||||||
|
|
Loading…
Reference in a new issue