management.views.backup

Django backup view.

Classes

BackupManageView

Display existing backups and handle backup-related actions.

BackupFileDownloadView

Serve a single backup file for download.

BackupFilesDownloadMultipleView

Download multiple selected backup files as a ZIP or tar.gz archive.

BackupFilesDeleteMultipleView

Delete multiple selected backup files and notify the user.

Functions

get_backup_file_data(filename)

Retrieve metadata for a single backup file.

create_db_backup(path)

Create a compressed database backup file in the given directory.

Module Contents

management.views.backup.get_backup_file_data(filename)[source]

Retrieve metadata for a single backup file.

Parameters:

filename (str) – Name of the backup file.

Returns:

  • filename: str - created_at: str (formatted ‘YYYY-MM-DD HH:MM:SS’ in UTC) - modified_at: str (formatted ‘YYYY-MM-DD HH:MM:SS’ in UTC) - size_kb: str (size in KB to one decimal place)

Returns an empty dict if the file does not exist or is not a regular file.

Return type:

A dict with keys

management.views.backup.create_db_backup(path)[source]

Create a compressed database backup file in the given directory.

The command manage.py dbbackup -o <filename> -z is used, producing a .dump.gz file under path.

Parameters:

path (pathlib.Path) – Directory where backups should be stored.

Returns:

The filename of the created backup file.

Raises:
  • OSError – If path cannot be created.

  • CalledProcessError – If the dbbackup command fails.

Return type:

str

class management.views.backup.BackupManageView(**kwargs)[source]

Bases: trustpoint.views.base.SortableTableFromListMixin, trustpoint.logger.LoggerMixin, django.views.generic.ListView

Display existing backups and handle backup-related actions.

GET:
  • Renders a table of existing backup files.

  • Includes a form for editing SFTP/backup settings.

POST:
Depending on which button was clicked, performs one of:
  • create_local_backup: Creates a new database backup locally.

  • create_sftp_backup: Creates a new database backup and uploads via SFTP.

  • test_sftp_connection: Validates SFTP credentials without saving them.

  • save_backup_settings: Saves or updates BackupOptions.

  • reset_backup_settings: Deletes existing BackupOptions, reverting to defaults.

template_name = 'management/backups/manage_backups.html'[source]
context_object_name = 'backup_files'[source]
paginate_by = 20[source]
default_sort_param = 'filename'[source]
success_url[source]
get_queryset()[source]

Collect metadata for all backup_*.dump.gz files under BACKUP_FILE_PATH.

Return type:

Any

get_context_data(**kwargs)[source]

Add the BackupOptions form to the template context.

Parameters:

kwargs (Any)

Return type:

dict[str, Any]

post(request, *_args, **_kwargs)[source]

Handle form submissions for backup or SFTP settings.

Parameters:
  • request (Any)

  • _args (Any)

  • _kwargs (Any)

Return type:

django.http.HttpResponse

_handle_create_local_backup(request)[source]

Create a new backup file locally only.

Parameters:

request (Any)

Return type:

django.http.HttpResponse

_handle_create_sftp_backup(request)[source]

Create a new backup file and upload it via SFTP.

Parameters:

request (Any)

Return type:

django.http.HttpResponse

_handle_test_sftp(request)[source]

Logic for testing SFTP connection without saving settings.

Parameters:

request (Any)

Return type:

django.http.HttpResponse

_handle_save_settings(request)[source]

Logic for saving or updating backup/SFTP settings.

Parameters:

request (Any)

Return type:

django.http.HttpResponse

_handle_reset_settings(request)[source]

Logic for resetting (deleting) backup/SFTP settings.

Parameters:

request (Any)

Return type:

django.http.HttpResponse

class management.views.backup.BackupFileDownloadView(**kwargs)[source]

Bases: django.views.generic.View

Serve a single backup file for download.

get(_request, filename)[source]

Return the requested backup file as an attachment.

Parameters:
  • _request (Any) – The HTTP request (unused).

  • filename (str) – Name of the backup file to download.

Returns:

An HttpResponse with the file contents.

Raises:

Http404 – If the requested file does not exist.

Return type:

django.http.HttpResponse

class management.views.backup.BackupFilesDownloadMultipleView(**kwargs)[source]

Bases: django.views.generic.View

Download multiple selected backup files as a ZIP or tar.gz archive.

post(request, archive_format)[source]

Bundle selected backups into an archive.

Parameters:
  • request (Any) – The HTTP request, containing POST data ‘selected’ (a list of filenames).

  • archive_format (str) – Either ‘zip’ or ‘tar.gz’.

Returns:

An HttpResponse containing the archive.

Raises:

Redirect to management – backups with an error if no valid files are selected.

Return type:

django.http.HttpResponse

class management.views.backup.BackupFilesDeleteMultipleView(**kwargs)[source]

Bases: django.views.generic.View, trustpoint.logger.LoggerMixin

Delete multiple selected backup files and notify the user.

post(request)[source]

Delete the selected backup files.

Parameters:

request (Any) – The HTTP request, containing POST data ‘selected’ (list of filenames).

Returns:

An HttpResponse redirecting back to the backups page.

Return type:

django.http.HttpResponse