简体   繁体   中英

How do I automatically backup db.sqlite3 file in Django App hosted on Azure Web Apps?

I have a Django web application hosted on _________.azurewebsites.net

The folder structure is as follows:

- Github Repository
     - settingsFolder
     - app1folder
     - app2folder
     - manage.py 
     - web.config
     - db.sqlite3

I have Azure set up to where a push to my remote github branch causes Azure to sync the files with my Github branch to my /site/wwwroot/ folder.

Explicitly,

git push origin branch 

This causes a problem. Everytime I try to add changes to my website, using git push, the db.sqlite3 DOES NOT reflect the changes within the website environment. Thus, if someone were to save data to /site/wwwroot/db.sqlite3, then my github repository would be UNAWARE of the changes. Updating my github repository would take the OLD db.sqlite3 and reupload THIS OLD during a file sync between Azure and github. Consequently, the db.sqlite3 on /site/wwwroot/ gets overwritten and data would be lost.

One solution is to manually make backups by connecting to my /site/wwwroot folder, saving db.sqlite3, and replacing it regularly in my Github repository.

Is it possible to automate this? If so, what resources does Azure provide me to do so?

What you're doing is wrong in quite a few ways.

Firstly, your sqlite file should not be in version control. Your local db is just that, local; it shouldn't be deployed to production, for exactly the reason you're experiencing. Delete it from git and ensure it is in your .gitignore file.

Secondly, it's not really appropriate to use a file-based db in production. Sqlite is a great tool but as soon as you move to a real production site you need a real database. Apart from anything else, if you find you need to scale your site to more than one Azure instance, they will each have a separate copy of the database file, so data will quickly get out of sync. Use a real db like PostgreSQL; yet another benefit of that is that your host will take care of backing it up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM