-2

I'm trying to trigger a database backup from a button in a custom view I have created in Django. The thing is that in all the information I have found about database backups, the command is triggered automatically or from a manage.py command.

Any ideas about how to solve it? It's even possible to execute a manage.py command from a view?

1 Answers1

1

Yes, it is possible to execute manage.py command from view. Look at this section on django documentation.

But real problem is if you should do that or not. Backing-up database takes time and executing any command inside your view will force django to wait for that command finishes before sending reponse back to your browser. And for that execution time, one of your workers will be busy and won't take any requests.

If, by mistake, you will execute your view several times, you can block all of your workers, so your website won't be accessible before backups finishes.

Consider using some off-loading or background tasks like Celery, uWSGI spooler or just don't use views for that.

GwynBleidD
  • 20,081
  • 5
  • 46
  • 77