Compare commits

...

11 Commits

9 changed files with 149 additions and 33 deletions

View File

@ -0,0 +1,63 @@
# Generated by Django 4.0.6 on 2022-10-05 18:27
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('borg', '0003_label_visible'),
]
operations = [
migrations.AlterField(
model_name='archive',
name='compressed_size',
field=models.BigIntegerField(),
),
migrations.AlterField(
model_name='archive',
name='deduplicated_size',
field=models.BigIntegerField(),
),
migrations.AlterField(
model_name='archive',
name='file_count',
field=models.BigIntegerField(),
),
migrations.AlterField(
model_name='archive',
name='original_size',
field=models.BigIntegerField(),
),
migrations.AlterField(
model_name='cache',
name='total_chunks',
field=models.BigIntegerField(),
),
migrations.AlterField(
model_name='cache',
name='total_csize',
field=models.BigIntegerField(),
),
migrations.AlterField(
model_name='cache',
name='total_size',
field=models.BigIntegerField(),
),
migrations.AlterField(
model_name='cache',
name='total_unique_chunks',
field=models.BigIntegerField(),
),
migrations.AlterField(
model_name='cache',
name='unique_csize',
field=models.BigIntegerField(),
),
migrations.AlterField(
model_name='cache',
name='unique_size',
field=models.BigIntegerField(),
),
]

View File

@ -8,9 +8,9 @@ class Archive(models.Model):
name = models.TextField()
start = models.DateTimeField()
end = models.DateTimeField()
file_count = models.IntegerField()
original_size = models.IntegerField()
compressed_size = models.IntegerField()
deduplicated_size = models.IntegerField()
file_count = models.BigIntegerField()
original_size = models.BigIntegerField()
compressed_size = models.BigIntegerField()
deduplicated_size = models.BigIntegerField()
cache = models.OneToOneField(Cache, on_delete=models.CASCADE)

View File

@ -2,9 +2,9 @@ from django.db import models
class Cache(models.Model):
total_chunks = models.IntegerField()
total_csize = models.IntegerField()
total_size = models.IntegerField()
total_unique_chunks = models.IntegerField()
unique_csize = models.IntegerField()
unique_size = models.IntegerField()
total_chunks = models.BigIntegerField()
total_csize = models.BigIntegerField()
total_size = models.BigIntegerField()
total_unique_chunks = models.BigIntegerField()
unique_csize = models.BigIntegerField()
unique_size = models.BigIntegerField()

View File

@ -102,7 +102,7 @@ class Repo(models.Model):
@staticmethod
def series_csize(archives, units=None):
return [convert_bytes(archive.cache.unique_csize, units)[0]
if archive is not None else None for archive in archives]
if archive is not None else 0 for archive in archives]
def hourly_archive_string(self):
return ''.join(['H' if archive is not None else '-' for archive in self.hourly_archives(8)])

View File

@ -3,10 +3,14 @@ from django.http import HttpResponseRedirect
from django.urls import reverse
from django.contrib.auth.decorators import permission_required
from django.core.cache import cache
from django.core.cache import cache as django_cache
from ..models import Repo, Label, Archive, Cache, Error, Location
from ..forms import RepoForm, ArchiveForm, ErrorForm, LocationForm, ToggleVisibility
import logging
logger = logging.getLogger(__file__)
@permission_required("borg.change_repo")
def toggle_visibility(request):
@ -20,7 +24,7 @@ def toggle_visibility(request):
label.visible = not label.visible
label.save()
cache.clear()
django_cache.clear()
return HttpResponseRedirect(reverse('index'))
else:
@ -49,7 +53,7 @@ def post_repo(request):
'last_modified': cdata['last_modified'],
'label': label})
repo.save()
cache.clear()
django_cache.clear()
return HttpResponseRedirect(reverse('index'))
else:
@ -63,6 +67,7 @@ def post_archive(request):
if request.method == 'POST':
form = ArchiveForm(request.POST)
if form.is_valid():
try:
cdata = form.cleaned_data
repo = get_object_or_404(Repo, label__label=cdata['label'])
@ -78,7 +83,9 @@ def post_archive(request):
archive = Archive(**archive_dict, repo=repo, cache=cache)
archive.save()
cache.clear()
django_cache.clear()
except Exception:
logger.exception("Archive post failed")
return HttpResponseRedirect(reverse('index'))
else:
@ -97,7 +104,7 @@ def post_error(request):
error = Error(label=label, error=cdata['error'], time=cdata['time'])
error.save()
cache.clear()
django_cache.clear()
return HttpResponseRedirect(reverse('index'))
else:
@ -115,7 +122,7 @@ def post_location(request):
label, _ = Location.objects.get_or_create(label=cdata['label'],
defaults={"path": cdata["path"]})
label.save()
cache.clear()
django_cache.clear()
return HttpResponseRedirect(reverse('index'))
else:

View File

@ -1 +1 @@
from .secrets import SECRET_KEY
from .secrets import SECRET_KEY, DATABASE_PASSWORD

View File

@ -2,6 +2,7 @@ import os
from pathlib import Path
from . import SECRET_KEY as __SECRET_KEY
from . import DATABASE_PASSWORD as __DATABASE_PASSWORD
BASE_DIR = Path(__file__).resolve().parent.parent
@ -9,9 +10,11 @@ SECRET_KEY = __SECRET_KEY
DEBUG = False
AXES_META_PRECEDENCE_ORDER = ('HTTP_X_FORWARDED_FOR', 'X_FORWARDED_FOR', 'REMOTE_ADDR')
AXES_LOCKOUT_CALLABLE = "borg.views.axes"
ALLOWED_HOSTS = ['127.0.0.1', 'borg.george.ooo', 'george.ooo', 'www.george.ooo']
ALLOWED_HOSTS = ['127.0.0.1', 'borg.george.ooo', 'george.ooo', 'www.george.ooo', '10.10.10.100', 'proxy.george.ooo']
AUTHENTICATION_BACKENDS = [
'axes.backends.AxesBackend',
@ -65,8 +68,12 @@ WSGI_APPLICATION = 'borgweb.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': "/home/web/sites/db/borg.db",
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'borgweb',
'USER': 'borgweb',
'PASSWORD': __DATABASE_PASSWORD,
'HOST': 'db.george.ooo',
'PORT': '5432',
}
}
@ -120,7 +127,7 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"LOCATION": "redis://cache.george.ooo:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient"
},
@ -128,6 +135,36 @@ CACHES = {
}
}
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"root": {"level": "INFO", "handlers": ["file"]},
"handlers": {
"file": {
"level": "INFO",
"class": "logging.FileHandler",
"filename": "/var/log/django/borgweb.log",
"formatter": "app",
},
},
"loggers": {
"django": {
"handlers": ["file"],
"level": "INFO",
"propagate": True
},
},
"formatters": {
"app": {
"format": (
u"%(asctime)s [%(levelname)-8s] "
"(%(module)s.%(funcName)s) %(message)s"
),
"datefmt": "%Y-%m-%d %H:%M:%S",
},
},
}
# security
SESSION_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = True

View File

@ -35,7 +35,7 @@ print_action "Installing pip packages, this may take a while..."
# install required pip packages
yes | python -m pip install --upgrade wheel
yes | python -m pip install django gunicorn django-libsass django-compressor django-axes django-redis
yes | python -m pip install django gunicorn django-libsass django-compressor django-axes django-redis psycopg2-binary
print_action "Setting up static files and database"

9
borgweb/update.sh Normal file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
cd "${0%/*}"
source ./venv/bin/activate
python ./manage.py collectstatic --noinput
python ./manage.py compress
python ./manage.py migrate --noinput
deactivate