management.views.backup¶
Django backup view.
Classes¶
Display existing backups and handle backup-related actions. |
|
Serve a single backup file for download. |
|
Download multiple selected backup files as a ZIP or tar.gz archive. |
|
Delete multiple selected backup files and notify the user. |
Functions¶
|
Retrieve metadata for a single backup file. |
|
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.ListViewDisplay 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.
- 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
- class management.views.backup.BackupFileDownloadView(**kwargs)[source]¶
Bases:
django.views.generic.ViewServe 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.ViewDownload 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.LoggerMixinDelete multiple selected backup files and notify the user.