Package: django-project-backup
django-project-backupDjango project backup application.(This is alpha software and is under heavy development)SetupAdd the following lines tosettings.py# djangoINSTALLED_APPS+=['django_project_backup']# django-project-backupSERIALIZATION_MODULES={'dpb_couchdb_datastore':'django_project_backup.utils.couchdb.serializers'}DJANGO_PROJECT_BACKUP_MODE=env('DJANGO_PROJECT_BACKUP_MODE',default='incremental')DJANGO_PROJECT_BACKUP_PROJECT_NAME=env('DJANGO_PROJECT_BACKUP_PROJECT_NAME',default='django_project_backup')DJANGO_PROJECT_BACKUP_SHARD_NAME=env('DJANGO_PROJECT_BACKUP_SHARD_NAME',default='1')# realtimeDJANGO_PROJECT_BACKUP_REALTIME=env.bool('DJANGO_PROJECT_BACKUP_REALTIME',default=True)DJANGO_PROJECT_BACKUP_DO_REALTIME_COUCHDB_BACKUP=env.bool('DJANGO_PROJECT_BACKUP_DO_REALTIME_COUCHDB_BACKUP',default=True)DJANGO_PROJECT_BACKUP_DO_REALTIME_LOG_BACKUP=env.bool('DJANGO_PROJECT_BACKUP_DO_REALTIME_LOG_BACKUP',default=True)DJANGO_PROJECT_BACKUP_EXCLUDED_MODELS=env.list('DJANGO_PROJECT_BACKUP_EXCLUDED_MODELS',default=['sessions.session','admin.logentry','django_sso_app.passepartout','django_sso_app.device','easy_thumbnails.thumbnail'])DJANGO_PROJECT_BACKUP_PUBLIC_ASSETS_FOLDERS=env.list('DJANGO_PROJECT_BACKUP_PUBLIC_ASSETS_FOLDERS',default=[str(PUBLIC_ROOT)])DJANGO_PROJECT_BACKUP_PRIVATE_ASSETS_FOLDERS=env.list('DJANGO_PROJECT_BACKUP_PRIVATE_ASSETS_FOLDERS',default=[str(PRIVATE_ROOT)])DJANGO_PROJECT_BACKUP_DESTINATION_FOLDER=env('DJANGO_PROJECT_BACKUP_DESTINATION_FOLDER',default=os.path.join(ROOT_DIR,'backups'))DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_URL=env('DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_URL',default='http://127.0.0.1:5984')DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_USER=env('DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_USER',default='admin')DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_PASSWORD=env('DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_PASSWORD',default='couchdb')# couchdb db indexDJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_DATABASE_NAME=env('DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_DATABASE_NAME',default='django_project_backup')DJANGO_PROJECT_BACKUP_DO_FAILSAFE_BACKUP=env.bool('DJANGO_PROJECT_BACKUP_DO_FAILSAFE_BACKUP',default=True)DJANGO_PROJECT_BACKUP_FAILSAFE_BACKUP_PATH=env('DJANGO_PROJECT_BACKUP_FAILSAFE_BACKUP_PATH',default=os.path.join(DJANGO_PROJECT_BACKUP_DESTINATION_FOLDER,'failed'))# log realtimeLOGGING={..."formatters":{"dpb_serialized_model":{"format":"%(message)s"}},'handlers':{"dpb_realtime_log_backup_file":{"level":"INFO","class":"logging.handlers.RotatingFileHandler","filename":os.path.join(ROOT_DIR,"logs","django_project_backup.realtime.log"),"maxBytes":1024*1024*4000,# 4GB"backupCount":10,"formatter":"dpb_serialized_model",},},'loggers':{...'django_project_backup.backup_logger':{'handlers':['dpb_realtime_log_backup_file'],'level':'INFO','propagate':False,},},}# django-filer# store files as payloadFILER_DUMP_PAYLOAD=TrueUsageFilesystemBackup DB$ python manage.py dpb_filesystem_dumpdataBackup assets$ python manage.py dpb_filesystem_assets_backupCouchdbBackup all$ python manage.py dpb_couchdb_dumpdataRestore all$ python manage.py dpb_couchdb_loaddataSandboxDockerDependenciesDockerDocker ComposeInstallationRun the following commands:gitclonehttps://bitbucket.org/pai/django-project-backup.gitcddjango-project-backup# build containersdocker-composeup--build-d# start containersdocker-composeup# load initial datadocker-composerunapp/venv/bin/pythonmanage.pyload_initial_data# perform first backupdocker-composerunapp/venv/bin/pythonmanage.pydbp_couchdb_dumpdataThe demo site will now be accessible athttp://localhost:8000/and the django admin
interface athttp://localhost:8000/admin/.Log into the admin with the credentialsadmin / admin.Important:Thisdocker-compose.ymlis configured for local testing only, and isnotintended for production use.DebuggingTo tail the logs from the Docker containers in realtime, run:docker-composelogs-fSetup with VirtualenvYou can run the demo locally without setting up Docker and simply use Virtualenv, which is therecommended installation approachfor Django itself.DependenciesPython 3.6, 3.7 or 3.8VirtualenvVirtualenvWrapper(optional)InstallationWithPIPandvirtualenvwrapperinstalled, run:mkvirtualenv django_project_backup
python --versionConfirm that this is showing a compatible version of Python 3.x. If not, and you have multiple versions of Python installed on your system, you may need to specify the appropriate version when creating the virtualenv:deactivate
rmvirtualenv django_project_backup
mkvirtualenv django_project_backup --python=python3.7
python --versionNow we're ready to set up the sandbox demo project itself:cd ~/dev [or your preferred dev directory]
git clone https://bitbucket.org/pai/django-project-backup.git
cd django_project_backup/
pip install -r requirements/base.txtNext, we'll set up our local environment variables. We usedjango-dotenvto help with this. It reads environment variables located in a file name.envin the top level directory of the project.
The only variable we need to start isDJANGO_SETTINGS_MODULE:$ cp backend/settings/local.py.example backend/settings/local.py
$ echo "DJANGO_SETTINGS_MODULE=backend.settings.local" > .envTo set up your database and load initial data, run the following commands:./manage.py migrate
./manage.py load_initial_data
./manage.py runserverLog into the admin with the credentialsadmin / admin.Known issuesSince django-project-backup relies on natural primary keys when inrealtimemode if one of those fields
is updated there is no efficient way to update related objects keys.NoteThis project has been set up using PyScaffold 3.2.3. For details and usage
information on PyScaffold seehttps://pyscaffold.org/.