mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Backup enhancements (#7077)
* Update backup docs * Add note on advanced usage * Add extra options for backup and restore * Update restore task
This commit is contained in:
parent
50ca493667
commit
3f80a45cb5
@ -8,6 +8,9 @@ Backup functionality is provided natively using the [django-dbbackup library](ht
|
|||||||
|
|
||||||
Note that a *backup* operation is not the same as [migrating data](./migrate.md). While data *migration* exports data into a database-agnostic JSON file, *backup* exports a native database file and media file archive.
|
Note that a *backup* operation is not the same as [migrating data](./migrate.md). While data *migration* exports data into a database-agnostic JSON file, *backup* exports a native database file and media file archive.
|
||||||
|
|
||||||
|
!!! warning "Database Version"
|
||||||
|
When performing backup and restore operations, it is *imperative* that you are running from the same installed version of InvenTree. Different InvenTree versions may have different database schemas, which render backup / restore operations incompatible.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
The following configuration options are available for backup:
|
The following configuration options are available for backup:
|
||||||
@ -22,22 +25,31 @@ The following configuration options are available for backup:
|
|||||||
|
|
||||||
If you want to use an external storage provider, extra configuration is required. As a starting point, refer to the [django-dbbackup documentation](https://django-dbbackup.readthedocs.io/en/master/storage.html).
|
If you want to use an external storage provider, extra configuration is required. As a starting point, refer to the [django-dbbackup documentation](https://django-dbbackup.readthedocs.io/en/master/storage.html).
|
||||||
|
|
||||||
Specific storage configuration options are specified using the `backup_options` dict (in the [configuration file](./config.md)).
|
Specific storage configuration options are specified using the `backup_options` dict (in the [configuration file](./config.md#backup-file-storage)).
|
||||||
|
|
||||||
## Perform Backup
|
## Perform Backup
|
||||||
|
|
||||||
#### Manual Backup
|
#### Manual Backup
|
||||||
|
|
||||||
To perform a manual backup operation, run the following command from the shell:
|
To perform a basic manual backup operation, run the following command from the shell:
|
||||||
|
|
||||||
```
|
```
|
||||||
invoke backup
|
invoke backup
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This will perform backup operation with the default parameters. To see all available backup options, run:
|
||||||
|
|
||||||
|
```
|
||||||
|
invoke backup --help
|
||||||
|
```
|
||||||
|
|
||||||
### Backup During Update
|
### Backup During Update
|
||||||
|
|
||||||
When performing an update of your InvenTree installation - via either [docker](./docker.md) or [bare metal](./install.md) - a backup operation is automatically performed.
|
When performing an update of your InvenTree installation - via either [docker](./docker.md) or [bare metal](./install.md) - a backup operation is automatically performed.
|
||||||
|
|
||||||
|
!!! info "Skip Backup Step"
|
||||||
|
You can opt to skip the backup step during the update process by adding the `--skip-backup` option.
|
||||||
|
|
||||||
### Daily Backup
|
### Daily Backup
|
||||||
|
|
||||||
If desired, InvenTree can be configured to perform automated daily backups. The run-time setting to control this is found in the *Server Configuration* tab.
|
If desired, InvenTree can be configured to perform automated daily backups. The run-time setting to control this is found in the *Server Configuration* tab.
|
||||||
@ -56,3 +68,16 @@ To restore from a previous backup, run the following command from the shell (wit
|
|||||||
```
|
```
|
||||||
invoke restore
|
invoke restore
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To see all available options for restore, run:
|
||||||
|
|
||||||
|
```
|
||||||
|
invoke restore --help
|
||||||
|
```
|
||||||
|
|
||||||
|
## Advanced Usage
|
||||||
|
|
||||||
|
Not all functionality of the db-backup library is exposed by default. For advanced usage (not covered by the documentation above), refer to the [django-dbbackup commands documentation](https://django-dbbackup.readthedocs.io/en/master/commands.html).
|
||||||
|
|
||||||
|
!!! warning "Advanced Users Only"
|
||||||
|
Any advanced usage assumes some underlying knowledge of django, and is not documented here.
|
||||||
|
71
tasks.py
71
tasks.py
@ -360,22 +360,73 @@ def translate(c, ignore_static=False, no_frontend=False):
|
|||||||
static(c)
|
static(c)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task(
|
||||||
def backup(c):
|
help={
|
||||||
|
'clean': 'Clean up old backup files',
|
||||||
|
'path': 'Specify path for generated backup files (leave blank for default path)',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
def backup(c, clean=False, path=None):
|
||||||
"""Backup the database and media files."""
|
"""Backup the database and media files."""
|
||||||
print('Backing up InvenTree database...')
|
print('Backing up InvenTree database...')
|
||||||
manage(c, 'dbbackup --noinput --clean --compress')
|
|
||||||
|
cmd = '--noinput --compress -v 2'
|
||||||
|
|
||||||
|
if path:
|
||||||
|
cmd += f' -O {path}'
|
||||||
|
|
||||||
|
if clean:
|
||||||
|
cmd += ' --clean'
|
||||||
|
|
||||||
|
manage(c, f'dbbackup {cmd}')
|
||||||
print('Backing up InvenTree media files...')
|
print('Backing up InvenTree media files...')
|
||||||
manage(c, 'mediabackup --noinput --clean --compress')
|
manage(c, f'mediabackup {cmd}')
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task(
|
||||||
def restore(c):
|
help={
|
||||||
|
'path': 'Specify path to locate backup files (leave blank for default path)',
|
||||||
|
'db_file': 'Specify filename of compressed database archive (leave blank to use most recent backup)',
|
||||||
|
'media_file': 'Specify filename of compressed media archive (leave blank to use most recent backup)',
|
||||||
|
'ignore_media': 'Do not import media archive (database restore only)',
|
||||||
|
'ignore_database': 'Do not import database archive (media restore only)',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
def restore(
|
||||||
|
c,
|
||||||
|
path=None,
|
||||||
|
db_file=None,
|
||||||
|
media_file=None,
|
||||||
|
ignore_media=False,
|
||||||
|
ignore_database=False,
|
||||||
|
):
|
||||||
"""Restore the database and media files."""
|
"""Restore the database and media files."""
|
||||||
print('Restoring InvenTree database...')
|
base_cmd = '--no-input --uncompress -v 2'
|
||||||
manage(c, 'dbrestore --noinput --uncompress')
|
|
||||||
print('Restoring InvenTree media files...')
|
if path:
|
||||||
manage(c, 'mediarestore --noinput --uncompress')
|
base_cmd += f' -I {path}'
|
||||||
|
|
||||||
|
if ignore_database:
|
||||||
|
print('Skipping database archive...')
|
||||||
|
else:
|
||||||
|
print('Restoring InvenTree database')
|
||||||
|
cmd = f'dbrestore {base_cmd}'
|
||||||
|
|
||||||
|
if db_file:
|
||||||
|
cmd += f' -i {db_file}'
|
||||||
|
|
||||||
|
manage(c, cmd)
|
||||||
|
|
||||||
|
if ignore_media:
|
||||||
|
print('Skipping media restore...')
|
||||||
|
else:
|
||||||
|
print('Restoring InvenTree media files')
|
||||||
|
cmd = f'mediarestore {base_cmd}'
|
||||||
|
|
||||||
|
if media_file:
|
||||||
|
cmd += f' -i {media_file}'
|
||||||
|
|
||||||
|
manage(c, cmd)
|
||||||
|
|
||||||
|
|
||||||
@task(post=[rebuild_models, rebuild_thumbnails])
|
@task(post=[rebuild_models, rebuild_thumbnails])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user