Skip to content

Instantly share code, notes, and snippets.

@m7salam
Last active December 25, 2023 04:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m7salam/bccac6780843a6330633d0c2965e8d29 to your computer and use it in GitHub Desktop.
Save m7salam/bccac6780843a6330633d0c2965e8d29 to your computer and use it in GitHub Desktop.
cookiecutter-django backup restore guide
steps to restore backups smoothly
=================================
** you must be logged in to the production server for this commands to working
#Side Note : dprod is an alias should be availabe in .bashrc, so any "dprod" command can be replaced with the following:
::
alias dprod="docker-compose -f production.yml"
# create backup and upload it to aws:
-------------------------------------
::
./production_backup_upload.sh
# Destroy the containters and volumes ( Destroy all )
-----------------------------------------------------
::
dprod-kill
# Build the server and restore
------------------------------
::
dprod-build
dprod-up postgres
dprod-backup-download $BACKUP_FILE_NAME
docker ps #to get postgres container ID
dprod-copy-backups $POSTGRES_CONTAINER_ID #this will create a backups/ folder in the current working directory
dprod-backup-restore $BACKUP_FILE_NAME
dprod-up-build
dprod-migrate
# in case you added new models or apps
--------------------------------------
::
dprod run --rm django python manage.py migrate <app-name>
# in case of reset migrations
-----------------------------
# (run migrate --fake for each app's migration that was migrated before the backup restore)
# this is individual commands to be used
::
dprod run --rm django python manage.py migrate --fake <previously-migrated-app>
# examples
::
dprod run --rm django python manage.py migrate --fake users
dprod run --rm django python manage.py migrate --fake sales
dprod run --rm django python manage.py migrate --fake finance
dprod run --rm django python manage.py migrate --fake billing
dprod run --rm django python manage.py migrate --fake invites
dprod run --rm django python manage.py migrate --fake global_settings
dprod run --rm django python manage.py migrate --fake reports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment