From d4bbc367953a01130a510f476cb59e5225b86960 Mon Sep 17 00:00:00 2001 From: Johannes Erwerle Date: Mon, 13 Apr 2026 21:11:28 +0200 Subject: [PATCH] added DATABASES setting --- README.md | 109 +++++++++++++++++- .../community_backup/example_configuration.py | 7 ++ community_backup/community_backup/settings.py | 16 +-- 3 files changed, 119 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 995a282..f6af251 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,111 @@ A website to manage backup repositories. ## Installation -TODO +This installation guide assumes a Debian 13 system. + +Install Python and several dependencies: + +This example should wo + +```bash +apt update && apt install python3 python3-pip python3-venv borgbackup +``` + +Clone the repository + +git clone https://git.srvspace.net/jo/community-backup.git + +Or install from a release + +Create a venv + +```bash +python3 -m venv venv +``` + +Activea the venv + +```bash +source venv/bin/activate +``` + +Install the package and it's dependencies: + +```bash +pip install -e community-backup +``` + +Create a configuration file in `community_backup/community_backup/community_backup/configration.py`, e.g. by copying and adjusting the `example_configuraton.py` next to that location. + +The settings are explained in detail in the setting section. + +Apply the migrations: + +```bash +python community-backup/community_backup/manage.py migrate +``` + +Collect the static files: + +```bash +# python community-backup/community_backup/manage.py collectstatic + +130 static files copied to '/opt/community_backup/static'. +``` + +Point your webserver to the static files. E.g. with caddy: + +``` +example.backups.org { + handle /static/* { + file_server { + root /opt/community_backup/ + } + } + + handle { + reverse_proxy http://localhost:8000 + } +} +``` + +Create a superuser account + +``` + +``` + +## Settings + +### BACKUP_USER + +`BACKUP_USER` specifies the username, that is used for borg backups. This user is used for various file permissions as well as the user that clients are using to log in and push their backups. + +### BACKUP_REPO_HOST + +`BACKUP_REPO_HOST` is the hostname given to the user for pushing their backups to. E.g. `backup.example.com`. + +### BACKUP_HOME_DIR + +`BACKUP_HOME_DIR` is the home directory of the borg user. This must be a `pathlib.Path`. + +### BACKUP_BORG_DIR + +`BACKUP_BORG_DIR` is the directory in which the actual backups are stored. This must be a `pathlib.Path` + +### BACKUP_AUTHORIZED_KEYS + +`BACKUP_AUTHORIZED_KEYS` is the authorized_keys file of the SSH daemon used for `BORG_USER`. This must be a `pathlib.Path` + +### DATABASES + +`DATABASES` is the Django database setting. Here is an example for sqlite3. + +``` +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": "/some/path/to/db.sqlite3", + } +} +``` diff --git a/community_backup/community_backup/example_configuration.py b/community_backup/community_backup/example_configuration.py index ca5f4c6..fec60ea 100644 --- a/community_backup/community_backup/example_configuration.py +++ b/community_backup/community_backup/example_configuration.py @@ -6,3 +6,10 @@ BACKUP_BORG_DIR = BACKUP_HOME_DIR / "borg" BACKUP_AUTHORIZED_KEYS = BACKUP_HOME_DIR / ".ssh" / "authorized_keys" BACKUP_USER = "borg" BACKUP_REPO_HOST = "backup.example.com" + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": "/path/to/the/db.sqlite3", + } +} diff --git a/community_backup/community_backup/settings.py b/community_backup/community_backup/settings.py index 8b45b50..47514da 100644 --- a/community_backup/community_backup/settings.py +++ b/community_backup/community_backup/settings.py @@ -79,17 +79,6 @@ TEMPLATES = [ WSGI_APPLICATION = "community_backup.wsgi.application" -# Database -# https://docs.djangoproject.com/en/6.0/ref/settings/#databases - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", - } -} - - # Password validation # https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators @@ -139,7 +128,9 @@ try: assert module.BACKUP_REPO_HOST, "The BACKUP_REPO_HOST setting is required." assert module.BACKUP_HOME_DIR, "The BACKUP_HOME_DIR setting is required." assert module.BACKUP_BORG_DIR, "The BACKUP_BORG_DIR setting is required." - assert module.BACKUP_AUTHORIZED_KEYS, "The BACKUP_AUTHORIZED_KEYS setting is required." + assert module.BACKUP_AUTHORIZED_KEYS, ( + "The BACKUP_AUTHORIZED_KEYS setting is required." + ) except ModuleNotFoundError: print(f"could not find configuration file {config_module}") @@ -150,3 +141,4 @@ BACKUP_REPO_HOST = module.BACKUP_REPO_HOST BACKUP_HOME_DIR = module.BACKUP_HOME_DIR BACKUP_BORG_DIR = module.BACKUP_BORG_DIR BACKUP_AUTHORIZED_KEYS = module.BACKUP_AUTHORIZED_KEYS +DATABASES = module.DATABASES