From 27f99d21e553373f9a2f90c3ec09e7ef1cedf97b Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sat, 24 Oct 2020 16:34:33 +0200 Subject: [PATCH] Add Django dbbackup https://github.com/django-dbbackup/django-dbbackup * use postgres v11 (because only this version exists in debian buster, too) * update to python v3.9 in compose usage --- .gitignore | 4 ++++ Dockerfile | 5 +++-- Makefile | 14 ++++++++++++++ README.creole | 2 ++ README.rst | 4 +++- docker-compose.yml | 2 +- inventory_project/settings.py | 7 +++++++ poetry.lock | 18 +++++++++++++++++- pyproject.toml | 1 + 9 files changed, 52 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index f5c364f..c76bc7e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,10 @@ !/.style.yapf !.coveralls.yml +# for django-dbbackup +/backups/ +!/backups/.gitkeep + # from test projects: /static/ /media/ diff --git a/Dockerfile b/Dockerfile index 59ee816..28db1f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,10 @@ -FROM python:3.7-slim-buster +FROM python:3.9-slim-buster +# https://hub.docker.com/_/python # Install deps RUN apt-get update \ && apt-mark auto $(apt-mark showinstall) \ - && apt-get install -y python3-pip \ + && apt-get install -y postgresql-client-11 python3-pip \ && apt autoremove \ && apt -y full-upgrade \ && rm -rf /var/lib/apt \ diff --git a/Makefile b/Makefile index 3a9cf4f..d159dbf 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,20 @@ logs_inventory: ## Display docker logs from postgres container ############################################################################## +dbbackup: ## Backup database + ./manage.sh dbbackup + +docker_dbbackup: ## Backup database (Docker usage) + ./compose.sh exec inventory ./manage.sh dbbackup + +dbrestore: ## Restore a database backup + ./manage.sh dbrestore + +docker_dbrestore: ## Restore a database backup (Docker usage) + ./compose.sh exec inventory ./manage.sh dbrestore + +############################################################################## + restart: down up ## Restart all containers upgrade_inventory: ## Upgrade "inventory" container and restart it diff --git a/README.creole b/README.creole index 51c6a7e..5e76486 100644 --- a/README.creole +++ b/README.creole @@ -76,6 +76,8 @@ down Stop all containers prune Cleanup docker build Update docker container build logs Display docker logs from all containers +dbbackup Backup database +dbrestore Restore a database backup restart Restart all containers }}} diff --git a/README.rst b/README.rst index 413ff21..15099e2 100644 --- a/README.rst +++ b/README.rst @@ -113,6 +113,8 @@ prepare prune Cleanup docker build Update docker container build logs Display docker logs from all containers + dbbackup Backup database + dbrestore Restore a database backup restart Restart all containers .env @@ -244,4 +246,4 @@ donation ------------ -``Note: this file is generated from README.creole 2020-10-24 14:31:12 with "python-creole"`` \ No newline at end of file +``Note: this file is generated from README.creole 2020-10-24 16:39:24 with "python-creole"`` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0a443b1..9f8a908 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: postgres: # https://hub.docker.com/_/postgres - image: postgres:13-alpine + image: postgres:11-alpine restart: "no" hostname: postgres ports: diff --git a/inventory_project/settings.py b/inventory_project/settings.py index 42bc4d6..edc0f3c 100644 --- a/inventory_project/settings.py +++ b/inventory_project/settings.py @@ -39,6 +39,7 @@ INSTALLED_APPS = [ 'bx_py_utils', # https://github.com/boxine/bx_py_utils 'import_export', # https://github.com/django-import-export/django-import-export + 'dbbackup', # https://github.com/django-dbbackup/django-dbbackup 'ckeditor', # https://github.com/django-ckeditor/django-ckeditor 'reversion', # https://github.com/etianen/django-reversion 'reversion_compare', # https://github.com/jedie/django-reversion-compare @@ -142,6 +143,12 @@ STATIC_ROOT = str(__Path(BASE_PATH, 'static')) MEDIA_URL = '/media/' MEDIA_ROOT = str(__Path(BASE_PATH, 'media')) +# _____________________________________________________________________________ +# Django-dbbackup + +DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage' +DBBACKUP_STORAGE_OPTIONS = {'location': str(__Path(BASE_PATH, 'backups'))} + # _____________________________________________________________________________ # Django-Debug-Toolbar diff --git a/poetry.lock b/poetry.lock index e8e425e..c427c37 100644 --- a/poetry.lock +++ b/poetry.lock @@ -258,6 +258,19 @@ python-versions = "*" [package.dependencies] django-js-asset = ">=1.2.2" +[[package]] +name = "django-dbbackup" +version = "3.3.0" +description = "Management commands to help backup and restore a project database and media" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +Django = ">=1.5" +pytz = "*" +six = "*" + [[package]] name = "django-debug-toolbar" version = "3.1.1" @@ -1178,7 +1191,7 @@ postgres = ["psycopg2-binary"] [metadata] lock-version = "1.1" python-versions = ">=3.7,<4.0.0" -content-hash = "4ad32caba18b4f973eee3d59a129b1ccd5750289a60c07939e1ab2f973fb4940" +content-hash = "d07f05b3cb200bb30974923869838af5e96a1935fdcbaa2e536f03f046583d90" [metadata.files] appdirs = [ @@ -1365,6 +1378,9 @@ django-ckeditor = [ {file = "django-ckeditor-6.0.0.tar.gz", hash = "sha256:29fd1a333cb9741ac2c3fd4e427a5c00115ed33a2389716a09af7656022dcdde"}, {file = "django_ckeditor-6.0.0-py2.py3-none-any.whl", hash = "sha256:cc2d377f1bdcd4ca1540caeebe85f7e2cd006198d57328ef6c718d3eaa5a0846"}, ] +django-dbbackup = [ + {file = "django-dbbackup-3.3.0.tar.gz", hash = "sha256:bb109735cae98b64ad084e5b461b7aca2d7b39992f10c9ed9435e3ebb6fb76c8"}, +] django-debug-toolbar = [ {file = "django-debug-toolbar-3.1.1.tar.gz", hash = "sha256:c97921a9cd421d392e7860dc4b464db8e06c8628df4dc58fedab012888c293c6"}, {file = "django_debug_toolbar-3.1.1-py3-none-any.whl", hash = "sha256:a1ce0665f7ef47d27b8df4b5d1058748e1f08500a01421a30d35164f38aaaf4c"}, diff --git a/pyproject.toml b/pyproject.toml index 3502c26..c92ee5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ gunicorn = "*" # https://gunicorn.org/ django = "2.2.*" django-debug-toolbar = "*" # http://django-debug-toolbar.readthedocs.io/en/stable/changes.html django-import-export = "*" # https://github.com/django-import-export/django-import-export +django-dbbackup = "*" # https://github.com/django-dbbackup/django-dbbackup django-tools = "*" # https://github.com/jedie/django-tools/ django-reversion-compare = "*" # https://github.com/jedie/django-reversion-compare/ django-ckeditor = "*" # https://github.com/django-ckeditor/django-ckeditor