From fd1d13f9af438dd47f5fec048129b282c42ac1e2 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 24 Dec 2024 10:14:48 -0800 Subject: [PATCH] backups: Use ISO timestamp for auto-naming archives Closes: #1603. - This introduces seconds and timezone in the name of the archive. When seconds are not used in the name, taking backups too quickly on after the other fails as the names clash. Tests: - Taking a backup works and creates the name in the expected ISO time format. - Changing the timezone and restarting service creates timestamps in that timezone. Reviewed-by: James Valleroy --- plinth/modules/backups/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plinth/modules/backups/views.py b/plinth/modules/backups/views.py index a05c73ac6..a7d1424dd 100644 --- a/plinth/modules/backups/views.py +++ b/plinth/modules/backups/views.py @@ -130,8 +130,11 @@ class CreateArchiveView(SuccessMessageMixin, FormView): if repository.flags.get('mountable'): repository.mount() - name = form.cleaned_data['name'] or datetime.now().strftime( - '%Y-%m-%d:%H:%M') + name = form.cleaned_data['name'] + if not name: + name = datetime.now().astimezone().replace( + microsecond=0).isoformat() + selected_apps = form.cleaned_data['selected_apps'] repository.create_archive(name, selected_apps) return super().form_valid(form)