99 ‐ Backups - l4rm4nd/VoucherVault GitHub Wiki

General Backup Strategy

The ./volume-data/database Docker bind mount volume holds all application data.

Within this bind mount directory, you will typically find:

  • The db.sqlite3 file if sqlite3 is used as database engine (default)
  • The psql directory, which holds your PostgreSQL database data if postgres is used as database engine
  • The uploads directory, which holds a subdirectory per user with user-specific file uploads (PDFs and images)

Therefore, by backing up this bind mount volume, all application data is saved.

[!WARNING] Read the official SQLite3 documentation or PostgreSQL documentation regarding backups.

Manual Backups via Django

You can also dump the database content manually using Django's manage.py.

This may help if something bricks and you have to re-import your application data into a freshly spawned VoucherVault container. Alternatively, if you switch database types and want to move your data to a new instance.

Proceed as follows:

Export data

# exec into the vouchervault container
docker exec -it vouchervault bash

# export database tables into outfile
python manage.py dumpdata auth.group > database/backup_db_table_groups.json
python manage.py dumpdata auth.user > database/backup_db_table_users.json
python manage.py dumpdata myapp.item > database/backup_db_table_items.json
python manage.py dumpdata myapp.transaction > database/backup_db_table_transactions.json

You will find the backup files within the Docker bind mount volume dir ./volume-data/database/.

Import data

# spawn a new vouchervault instance 
# copy export files to the bind mount volume

# exec into a new vouchervault container
docker exec -it vouchervault-new bash

# import old backup outfiles into new database
python manage.py loaddata database/backup_db_table_groups.json
python manage.py loaddata database/backup_db_table_users.json
python manage.py loaddata database/backup_db_table_items.json
python manage.py loaddata database/backup_db_table_transactions.json

Afterwards you can authenticate with your previous user accounts at the new VoucherVault instance. All previous application data will be available again.

[!WARNING] Ensure to transfer the ./database/uploads/ bind mount volume from the old instance to the new instance too. A simple copy operation does the job. This folder contains all user file uploads.