Skip to content

Backup-Cloud retention counter#3138

Open
Sleepwalker86 wants to merge 4 commits intoopenWB:masterfrom
Sleepwalker86:nextcloud_retention_counter
Open

Backup-Cloud retention counter#3138
Sleepwalker86 wants to merge 4 commits intoopenWB:masterfrom
Sleepwalker86:nextcloud_retention_counter

Conversation

@Sleepwalker86
Copy link
Contributor

@Sleepwalker86 Sleepwalker86 commented Feb 10, 2026

Implement a new function to enforce backup retention by deleting older backups on the SMB share when the number exceeds the specified limit. The maximum number of backups is now configurable via the SambaBackupCloudConfiguration class. This change ensures that only the most recent backups are retained, improving storage management.

Additionally, integrate the retention enforcement into the upload_backup function, handling potential errors during the cleanup process gracefully.
Enhance the Nextcloud backup module by introducing functions to list existing backups and enforce retention policies. The new `_list_backups` function retrieves backups based on a naming prefix, while `_enforce_retention` ensures that only a specified number of recent backups are retained. The `NextcloudBackupCloudConfiguration` class is updated to include a `max_backups` parameter for configuration. These changes improve backup management and storage efficiency.
@benderl benderl changed the title Nextcloud retention counter #2020 Backup-Cloud retention counter #2020 Feb 17, 2026
@benderl benderl changed the title Backup-Cloud retention counter #2020 Backup-Cloud retention counter Feb 17, 2026
@benderl
Copy link
Contributor

benderl commented Feb 17, 2026

Samba und Nextcloud

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a configurable retention limit for cloud backups so older backup generations can be cleaned up automatically (addresses #2020; UI change tracked in openwb-ui-settings#899).

Changes:

  • Add max_backups to Samba and Nextcloud backup cloud configuration objects.
  • Implement post-upload retention enforcement for Samba (SMB) by listing/deleting older backups.
  • Implement post-upload retention enforcement for Nextcloud via WebDAV PROPFIND + DELETE.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/modules/backup_clouds/samba/config.py Adds max_backups configuration field for Samba backups.
packages/modules/backup_clouds/samba/backup_cloud.py Adds SMB retention cleanup logic and invokes it after upload.
packages/modules/backup_clouds/nextcloud/config.py Adds max_backups configuration field for Nextcloud backups.
packages/modules/backup_clouds/nextcloud/backup_cloud.py Adds WebDAV-based retention cleanup logic and adjusts upload URL construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +51 to +55
# Präfix aus aktuellem Backup ableiten (alles vor dem ersten Punkt)
# Beispiel: openwb-backup-2026-02-10.tar.gz -> openwb-backup-2026-02-10
base_name = backup_filename.split("/")[-1]
base_prefix = base_name.split(".")[0]

Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die Retention-Filterlogik nutzt base_prefix = base_name.split(".")[0] und filtert anschließend mit startswith(base_prefix). Bei den realen Backup-Dateinamen (z.B. 2026-03-20_02-15-00_2.1.0.openwb-backup) ist der Teil vor dem ersten Punkt timestamp-/versionspezifisch, sodass praktisch nur das gerade hochgeladene Backup gematcht wird und alte Backups nie gelöscht werden. Bitte stattdessen nach einem stabilen Muster filtern (z.B. alle Dateien, die auf .openwb-backup bzw. .openwb-backup.gpg enden) und dann nach Dateiname sortieren/limitieren.

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +34
# Hier bleiben wir beim bisherigen Verhalten (/public.php/webdav/<filename>),
# d.h. base_path ist leer und backup_filename enthält ggf. Unterordner.
base_path = ""
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im else-Zweig (Benutzer/Passwort konfiguriert) wird base_path = "" gesetzt, aber der Kommentar sagt, dass beim bisherigen Verhalten (/public.php/webdav/<filename>) geblieben werden soll. Mit base_path="" wird aktuell jedoch nach f"{upload_url}/{backup_filename}" hochgeladen bzw. per PROPFIND/DELETE auf upload_url + "/" gearbeitet, was für eine normale Nextcloud-Installation sehr wahrscheinlich falsche Endpunkte sind. Bitte entweder base_path auch hier auf /public.php/webdav setzen (wie vorher) oder den korrekten DAV-Pfad für User-Accounts (/remote.php/dav/files/<user>/...) sauber implementieren.

Suggested change
# Hier bleiben wir beim bisherigen Verhalten (/public.php/webdav/<filename>),
# d.h. base_path ist leer und backup_filename enthält ggf. Unterordner.
base_path = ""
# Hier bleiben wir jedoch beim bisherigen Verhalten und nutzen ebenfalls
# den öffentlichen WebDAV-Pfad (/public.php/webdav/<filename>).
base_path = "/public.php/webdav"

Copilot uses AI. Check for mistakes.
Comment on lines +49 to +62
# Basispräfix der aktuellen Backup-Datei (z.B. "openwb-backup-2026-02-10" aus "openwb-backup-2026-02-10.tar.gz")
base_name = os.path.basename(backup_filename)
base_prefix = base_name.split(".")[0]

# Alle Einträge im Backup-Verzeichnis holen
entries = conn.listPath(config.smb_share, dir_path)

# Nur relevante Backup-Dateien herausfiltern
backup_files = [
e for e in entries
if not e.isDirectory
and e.filename not in (".", "..")
and e.filename.startswith(base_prefix)
]
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die Retention-Filterlogik nutzt base_prefix = base_name.split(".")[0] und filtert anschließend mit startswith(base_prefix). Die von runs/backup.sh generierten Dateinamen enthalten vor der Endung bereits weitere Punkte (Version), z.B. 2026-03-20_02-15-00_2.1.0.openwb-backup. Dadurch ist base_prefix timestamp-/versionspezifisch und matcht praktisch nur das aktuelle Backup – alte Dateien werden nicht gefunden und folglich nie gelöscht. Bitte stattdessen nach einem stabilen Muster filtern (z.B. Endung .openwb-backup/.openwb-backup.gpg) und dann das Limit anwenden.

Copilot uses AI. Check for mistakes.
Comment on lines +67 to +69
# Nach Änderungszeit sortieren (neueste zuerst)
backup_files.sort(key=lambda e: e.last_write_time, reverse=True)

Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im Issue #2020 wird gefordert, die zu löschenden Backups nach Dateiname zu sortieren (weil der Dateiname die zeitliche Reihenfolge abbildet). Hier wird stattdessen nach last_write_time sortiert. Das kann abweichen (z.B. wenn Dateien kopiert/verschoben wurden oder der Server-Timestamp unzuverlässig ist) und führt dann zu unerwarteten Löschungen. Bitte auf Sortierung nach Dateiname umstellen (oder klar begründen/konfigurierbar machen), damit das Verhalten dem Feature-Request entspricht.

Copilot uses AI. Check for mistakes.
@LKuemmel
Copy link
Contributor

Bitte die Kommentare vom Copilot-Review beachten.

Sleepwalker86 and others added 2 commits March 20, 2026 15:54
Update the backup retention mechanisms in both Nextcloud and Samba modules to use suffix-based filtering for backup filenames. The changes ensure that only files ending with ".openwb-backup" or ".openwb-backup.gpg" are considered for retention, improving accuracy in backup management. Additionally, comments have been enhanced for clarity regarding the implementation details and expected filename patterns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui depends on changes in ui repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants