mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 22:46:20 -05:00
* The backup drive keeps deleted files for 30 days, then removes them The fifth part of replacing the sync. A backup drive never deleted anything, so it grew forever and kept every file the media directory had ever held. Now, like a secondary: - A file deleted from the media directory, or the old version of one that changed, is moved to a dated folder in .backup-trash on the backup drive. Folders older than backup_delete_after_days (sync.yaml; 30 by default, also for drives set up before this; none never deletes) are removed, before and after each backup, and the oldest go sooner when the drive is nearly full. - A backup refuses a media directory that is not mounted, or has no config/wrolpi.yaml: copied with deletes, an empty folder would move the whole backup drive to the trash. - The Backup Drive panel has the same "Delete after N days / Never delete them" control as the Sync panel, now one component, and refuses an empty number of days. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * A nearly full drive keeps the trash it just filled, and makes room for the database Review found, in the backup drive's trash and in the secondary's sync, which share its shape: - Below 1 GiB free, the purge after a copy removed the newest trash folder too. Moving a file to the trash is a rename, which frees nothing, so on a nearly full drive a deleted file was gone at the end of the same run instead of 30 days later. The newest folder is now only removed by age (0 days still deletes at once). - The purge made room only down to 1 GiB, so a database larger than the free space failed to be copied every time while the trash was full. Before the database is written (the backup's snapshot, the secondary's copy of its primary's), the trash now makes room for the whole database. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.9 KiB
Python
43 lines
1.9 KiB
Python
from dataclasses import dataclass
|
|
from typing import List, Optional
|
|
|
|
from wrolpi.errors import ValidationError
|
|
|
|
|
|
@dataclass
|
|
class SyncDirectoriesRequest:
|
|
# The folder whose sub-folders are listed, relative to the media directory ('' is the media directory).
|
|
path: str = ''
|
|
# 'local' lists this WROLPi's media directory, 'primary' lists its primary's.
|
|
source: str = 'local'
|
|
|
|
def __post_init__(self):
|
|
if self.source not in ('local', 'primary'):
|
|
raise ValidationError("source must be 'local' or 'primary'")
|
|
|
|
|
|
@dataclass
|
|
class SyncSettingsRequest:
|
|
role: Optional[str] = None
|
|
sync_primary_url: Optional[str] = None
|
|
sync_window_start: Optional[str] = None
|
|
sync_window_end: Optional[str] = None
|
|
# The mount point of the backup drive, and the UUID of the drive that must be mounted there ('' clears both).
|
|
backup_directory: Optional[str] = None
|
|
backup_device_uuid: Optional[str] = None
|
|
backup_window_start: Optional[str] = None
|
|
backup_window_end: Optional[str] = None
|
|
# Days a secondary keeps a file its primary deleted or replaced; -1 never deletes.
|
|
sync_delete_after_days: Optional[int] = None
|
|
# Days the backup drive keeps a file deleted or replaced in the media directory; -1 never deletes.
|
|
backup_delete_after_days: Optional[int] = None
|
|
# Folders, relative to the media directory, never copied ([] clears).
|
|
sync_excluded_directories: Optional[List[str]] = None
|
|
backup_excluded_directories: Optional[List[str]] = None
|
|
|
|
def __post_init__(self):
|
|
if self.role is not None and self.role not in ('primary', 'secondary'):
|
|
raise ValidationError('role must be "primary" or "secondary"')
|
|
for key in ('sync_delete_after_days', 'backup_delete_after_days'):
|
|
if (value := getattr(self, key)) is not None and not -1 <= int(value) <= 3650:
|
|
raise ValidationError(f'{key} must be between 0 and 3650, or -1 to never delete')
|