Skip to content

Commit

Permalink
Merge branch 'master' into fix/0b-tempfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger authored Aug 23, 2024
2 parents 7155b6c + d8f09bd commit ebe043b
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 203 deletions.
2 changes: 1 addition & 1 deletion dbbackup/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.0
4.2.1
20 changes: 16 additions & 4 deletions dbbackup/db/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,23 @@ def restore_dump(self, dump):
if not self.connection.is_usable():
self.connection.connect()
cursor = self.connection.cursor()
sql_command = b""
sql_is_complete = True
for line in dump.readlines():
try:
cursor.execute(line.decode("UTF-8"))
except (OperationalError, IntegrityError) as err:
warnings.warn(f"Error in db restore: {err}")
sql_command = sql_command + line
line_str = line.decode("UTF-8")
if line_str.startswith("INSERT") and not line_str.endswith(");\n"):
sql_is_complete = False
continue
if not sql_is_complete and line_str.endswith(");\n"):
sql_is_complete = True

if sql_is_complete:
try:
cursor.execute(sql_command.decode("UTF-8"))
except (OperationalError, IntegrityError) as err:
warnings.warn(f"Error in db restore: {err}")
sql_command = b""


class SqliteCPConnector(BaseDBConnector):
Expand Down
12 changes: 10 additions & 2 deletions dbbackup/management/commands/dbrestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class Command(BaseDbBackupCommand):
help = "Restore a database backup from storage, encrypted and/or compressed."
content_type = "db"
no_drop = False

option_list = BaseDbBackupCommand.option_list + (
make_option("-d", "--database", help="Database to restore"),
Expand Down Expand Up @@ -52,6 +53,13 @@ class Command(BaseDbBackupCommand):
default=[],
help="Specify schema(s) to restore. Can be used multiple times.",
),
make_option(
"-r",
"--no-drop",
action="store_true",
default=False,
help="Don't clean (drop) the database. This only works with mongodb and postgresql.",
),
)

def handle(self, *args, **options):
Expand All @@ -74,6 +82,7 @@ def handle(self, *args, **options):
self.input_database_name
)
self.storage = get_storage()
self.no_drop = options.get("no_drop")
self.schemas = options.get("schema")
self._restore_backup()
except StorageError as err:
Expand Down Expand Up @@ -133,8 +142,7 @@ def _restore_backup(self):

input_file.seek(0)
self.connector = get_connector(self.database_name)

if self.schemas:
self.connector.schemas = self.schemas

self.connector.restore_dump(input_file)
self.connector.drop = not self.no_drop
1 change: 1 addition & 0 deletions dbbackup/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dbbackup",
"dbbackup.tests.testapp",
)
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

DATABASES = {
"default": {
Expand Down
12 changes: 11 additions & 1 deletion dbbackup/tests/test_connectors/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.test import TestCase

from dbbackup.db.sqlite import SqliteConnector, SqliteCPConnector
from dbbackup.tests.testapp.models import CharModel
from dbbackup.tests.testapp.models import CharModel, TextModel


class SqliteConnectorTest(TestCase):
Expand All @@ -28,7 +28,17 @@ def test_create_dump_with_unicode(self):
dump = connector.create_dump()
self.assertTrue(dump.read())

def test_create_dump_with_newline(self):
TextModel.objects.create(
field=f'INSERT ({"foo" * 5000}\nbar\n WHERE \nbaz IS\n "great" );\n'
)

connector = SqliteConnector()
dump = connector.create_dump()
self.assertTrue(dump.read())

def test_restore_dump(self):
TextModel.objects.create(field="T\nf\nw\nnl")
connector = SqliteConnector()
dump = connector.create_dump()
connector.restore_dump(dump)
Expand Down
1 change: 1 addition & 0 deletions dbbackup/tests/testapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class Migration(migrations.Migration):

initial = True
dependencies = []

operations = [
Expand Down
28 changes: 28 additions & 0 deletions dbbackup/tests/testapp/migrations/0002_textmodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.0.1 on 2022-04-27 22:36

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("testapp", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="TextModel",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("field", models.TextField()),
],
),
]
16 changes: 4 additions & 12 deletions dbbackup/tests/testapp/models.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
from django.db import models

___all__ = (
"CharModel",
"IntegerModel",
"TextModel",
"BooleanModel" "DateModel",
"DateTimeModel",
"ForeignKeyModel",
"ManyToManyModel",
"FileModel",
"TestModel",
)


class CharModel(models.Model):
field = models.CharField(max_length=10)


class TextModel(models.Model):
field = models.TextField()


class ForeignKeyModel(models.Model):
field = models.ForeignKey(CharModel, on_delete=models.CASCADE)

Expand Down
112 changes: 42 additions & 70 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Unreleased

* Nothing (yet)!

4.2.1 (2024-08-23)
----------

* Add --no-drop option to dbrestore command to prevent dropping tables before restoring data.
* Fix bug where sqlite dbrestore would fail if field data contains the line break character.

4.2.0 (2024-08-22)
------------------

Expand All @@ -20,91 +26,57 @@ Unreleased
4.1.0 (2024-01-14)
------------------

* Fix restore fail after editing filename by @stan-levend in https://github.com/jazzband/django-dbbackup/pull/465
* Drop python 3.6 by @Archmonger in https://github.com/jazzband/django-dbbackup/pull/472
* update links by @Arhell in https://github.com/jazzband/django-dbbackup/pull/471
* Update doc for backup directory consistency by @jej in https://github.com/jazzband/django-dbbackup/pull/473
* RESTORE_PREFIX for RESTORE_SUFFIX by @mativs in https://github.com/jazzband/django-dbbackup/pull/469
* Support Django 4.1, 4.2 and Python 3.11 by @johnthagen in https://github.com/jazzband/django-dbbackup/pull/485
* Support Python 3.12 and Django 5.0 by @johnthagen in https://github.com/jazzband/django-dbbackup/pull/499
* Fix restore fail after editing filename
* Drop python 3.6
* update links
* Update doc for backup directory consistency
* RESTORE_PREFIX for RESTORE_SUFFIX
* Support Django 4.1, 4.2 and Python 3.11
* Support Python 3.12 and Django 5.0

4.0.2 (2022-09-27)
------------------

* support for prometheus wrapped dbs by @tsundokum in https://github.com/jazzband/django-dbbackup/pull/455
* Backup of SQLite fail if there are Virtual Tables (e.g. FTS tables). by @xbello in https://github.com/jazzband/django-dbbackup/pull/458
* Closes #460: python-gnupg version increase breaks unencrypt_file func… by @chambersh1129 in https://github.com/jazzband/django-dbbackup/pull/461
* support for prometheus wrapped dbs
* Backup of SQLite fail if there are Virtual Tables (e.g. FTS tables).
* Closes #460: python-gnupg version increase breaks unencrypt_file func…

4.0.1 (2022-07-09)
---------------------

* As of this version, dbbackup is now within Jazzband! This version tests our Jazzband release CI, and adds miscellaneous refactoring/cleanup.
* Fix GitHub Actions configuration by @johnthagen in https://github.com/jazzband/django-dbbackup/pull/419
* Enable functional tests in CI by @johnthagen in https://github.com/jazzband/django-dbbackup/pull/420
* Update settings.py comment by @aaronvarghese in https://github.com/jazzband/django-dbbackup/pull/427
* Jazzband transfer tasks by @Archmonger in https://github.com/jazzband/django-dbbackup/pull/418
* Refactoring and tooling by @Archmonger in https://github.com/jazzband/django-dbbackup/pull/438
* Fix GitHub Actions configuration
* Enable functional tests in CI
* Update settings.py comment
* Jazzband transfer tasks
* Refactoring and tooling

4.0.0b0 (2021-12-19)
--------------------

* Fix RemovedInDjango41Warning related to default_app_config `#413`_
* Add authentication database support for MongoDB `#379`_
* Remove six dependency `#371`_
* Explicitly support Python 3.6+. `#408`_
* Drop support for end of life Django versions. Currently support 2.2, 3.2, 4.0. `#408`_
* Replace ugettext_lazy with gettext_lazy `#342`_
* Changed logging settings from settings.py to late init `#332`_
* Fix authentication error when postgres is password protected `#361`_
* Use exclude-table-data instead of exclude-table `#363`_
* Add support for exclude tables data in the command interface `#375`_
* Move author and version information into setup.py to allow building package in isolated
environment (e.g. with the ``build`` package). `#414`_
* Documentation fixes `#341`_ `#333`_ `#349`_ `#348`_ `#337`_ `#411`_
* Fix RemovedInDjango41Warning related to default_app_config
* Add authentication database support for MongoDB
* Remove six dependency
* Explicitly support Python 3.6+.
* Drop support for end of life Django versions. Currently support 2.2, 3.2, 4.0.
* Replace ugettext_lazy with gettext_lazy
* Changed logging settings from settings.py to late init
* Fix authentication error when postgres is password protected
* Use exclude-table-data instead of exclude-table
* Add support for exclude tables data in the command interface
* Move author and version information into setup.py to allow building package in isolated environment (e.g. with the ``build`` package).
* Documentation fixes


3.3.0 (2020-04-14)
------------------

* Documentation fixes `#341`_ `#333`_ `#328`_ `#320`_ `#305`_ `#303`_ `#302`_ `#298`_ `#281`_ `#266`_ `#349`_ `#348`_ `#337`_
* "output-filename" in mediabackup command `#324`_
* Fixes for test infrastructure and mongodb support `#318`_
* sqlite3: don't throw warnings if table already exists `#317`_
* Fixes for django3 and updated travis (and File handling) `#316`_
* Restoring from FTP `#313`_
* Fixes to run dbbackup management command in Postgres for non-latin Windows. `#273`_
* Apply changes from pull request 244; Update to include sftp storage `#280`_
* Quick fix for proper selection of DB name to restore `#260`_

.. _`#342`: https://github.com/jazzband/django-dbbackup/pull/342
.. _`#332`: https://github.com/jazzband/django-dbbackup/pull/332
.. _`#361`: https://github.com/jazzband/django-dbbackup/pull/361
.. _`#363`: https://github.com/jazzband/django-dbbackup/pull/363
.. _`#375`: https://github.com/jazzband/django-dbbackup/pull/375
.. _`#341`: https://github.com/jazzband/django-dbbackup/pull/341
.. _`#333`: https://github.com/jazzband/django-dbbackup/pull/333
.. _`#328`: https://github.com/jazzband/django-dbbackup/pull/328
.. _`#320`: https://github.com/jazzband/django-dbbackup/pull/320
.. _`#305`: https://github.com/jazzband/django-dbbackup/pull/305
.. _`#303`: https://github.com/jazzband/django-dbbackup/pull/303
.. _`#302`: https://github.com/jazzband/django-dbbackup/pull/302
.. _`#298`: https://github.com/jazzband/django-dbbackup/pull/298
.. _`#281`: https://github.com/jazzband/django-dbbackup/pull/281
.. _`#266`: https://github.com/jazzband/django-dbbackup/pull/266
.. _`#324`: https://github.com/jazzband/django-dbbackup/pull/324
.. _`#318`: https://github.com/jazzband/django-dbbackup/pull/318
.. _`#317`: https://github.com/jazzband/django-dbbackup/pull/317
.. _`#316`: https://github.com/jazzband/django-dbbackup/pull/316
.. _`#313`: https://github.com/jazzband/django-dbbackup/pull/313
.. _`#273`: https://github.com/jazzband/django-dbbackup/pull/273
.. _`#280`: https://github.com/jazzband/django-dbbackup/pull/280
.. _`#260`: https://github.com/jazzband/django-dbbackup/pull/260
.. _`#349`: https://github.com/jazzband/django-dbbackup/pull/349
.. _`#348`: https://github.com/jazzband/django-dbbackup/pull/348
.. _`#337`: https://github.com/jazzband/django-dbbackup/pull/337
.. _`#408`: https://github.com/jazzband/django-dbbackup/pull/408
.. _`#371`: https://github.com/jazzband/django-dbbackup/pull/371
.. _`#379`: https://github.com/jazzband/django-dbbackup/pull/379
.. _`#411`: https://github.com/jazzband/django-dbbackup/pull/411
.. _`#413`: https://github.com/jazzband/django-dbbackup/pull/413
.. _`#414`: https://github.com/jazzband/django-dbbackup/pull/414
* Documentation fixes
* "output-filename" in mediabackup command
* Fixes for test infrastructure and mongodb support
* sqlite3: don't throw warnings if table already exists
* Fixes for django3 and updated travis (and File handling)
* Restoring from FTP
* Fixes to run dbbackup management command in Postgres for non-latin Windows.
* Apply changes from pull request 244; Update to include sftp storage
* Quick fix for proper selection of DB name to restore
9 changes: 3 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

# General information about the project.
project = "django-dbbackup"
copyright = "2016, Michael Shepanski"
copyright = "Mark Bakhit"

# basepath
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -102,11 +102,8 @@

# -- Options for HTML output ---------------------------------------------------

on_rtd = os.environ.get("READTHEDOCS", None) == "True"
if on_rtd:
html_theme = "default"
else:
html_theme = "nature"
html_theme = "sphinx_rtd_theme"


# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down
8 changes: 0 additions & 8 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ It is made to:
- Keep your development database up to date
- Use Crontab or Celery to setup automated backups

.. warning::

Django DBBackup version 3 is very different to its predecessors.
See `Upgrade documentation`_ to help to get up to date.

.. _`Upgrade documentation`: upgrade.html

Contents:

.. toctree::
Expand All @@ -33,7 +26,6 @@ Contents:
storage
commands
integration
upgrade
contributing
changelog

Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ that are at least present when using PyPi repositories.

::

pip install -e git+https://github.com/mjs7231/django-dbbackup.git#egg=django-dbbackup
pip install -e git+https://github.com/jazzband/django-dbbackup.git#egg=django-dbbackup


Add it in your project
Expand Down
Loading

0 comments on commit ebe043b

Please sign in to comment.