简体   繁体   English

如何在Azure Web Apps上托管的Django App中自动备份db.sqlite3文件?

[英]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 我在_________.azurewebsites.net上托管了Django Web应用程序

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. 我在Azure上设置了对我的远程github分支的推送导致Azure将我的Github分支的文件同步到我的/ site / wwwroot /文件夹中。

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. 每次我尝试使用git push向我的网站添加更改时,db.sqlite3都不反映网站环境中的更改。 Thus, if someone were to save data to /site/wwwroot/db.sqlite3, then my github repository would be UNAWARE of the changes. 因此,如果有人要将数据保存到/site/wwwroot/db.sqlite3,则我的github存储库将是所做更改的UNAWARE。 Updating my github repository would take the OLD db.sqlite3 and reupload THIS OLD during a file sync between Azure and github. 更新我的github存储库将使用旧的db.sqlite3,并在Azure和github之间的文件同步期间重新上传此旧文件。 Consequently, the db.sqlite3 on /site/wwwroot/ gets overwritten and data would be lost. 因此,/ site / wwwroot /上的db.sqlite3被覆盖,数据将丢失。

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. 一种解决方案是通过连接到我的/ site / wwwroot文件夹,保存db.sqlite3并定期在我的Github存储库中替换它来手动进行备份。

Is it possible to automate this? 可以自动化吗? If so, what resources does Azure provide me to do so? 如果是这样,Azure为我提供了哪些资源?

What you're doing is wrong in quite a few ways. 您正在做的事情在很多方面都是错误的。

Firstly, your sqlite file should not be in version control. 首先,您的sqlite文件不应处于版本控制中。 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. 从git中删除它,并确保它在您的.gitignore文件中。

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. Sqlite是一个很棒的工具,但是一旦您移至真实的生产站点,就需要一个真实的数据库。 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. 除此之外,如果您发现需要将站点扩展到多个Azure实例,则它们每个都有一个单独的数据库文件副本,因此数据将迅速失去同步。 Use a real db like PostgreSQL; 使用像PostgreSQL这样的真实数据库; yet another benefit of that is that your host will take care of backing it up. 这样做的另一个好处是您的主机将负责备份它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 django 中重新安装 db.sqlite3 文件 - How do I reinstall the db.sqlite3 file in django 如何将默认的 Django 引擎数据库从 db.sqlite3 更改为填充了测试数据的 mysql 数据库? - How do I change the default Django engine database from db.sqlite3 to a mysql database populated with test data? 不忽略 db.sqlite3 文件,即使我在 django 项目中的 .gitignore 中指定 - Does not ignore db.sqlite3 file,even i specified in .gitignore in django project 我可以任意替换和还原db.sqlite3文件吗? - Can I arbitrarily replace and restore the db.sqlite3 file? 如何在 Visual Studio 中为 django 项目打开 db.sqlite3 - How to open db.sqlite3 in Visual studio for django project 如何不在 git 控制的 db.sqlite3 文件下部署 - How not to deploy under git controled db.sqlite3 file 如何修复“ django.db.utils.OperationalError:靠近“无”:语法错误” db.sqlite3? - How to fix 'django.db.utils.OperationalError: near “None”: syntax error' db.sqlite3? 使用PyCharm创建网站项目,但是找不到db.sqlite3文件 - Use PyCharm create a website project, but do not find the db.sqlite3 file 使用Django模型将Pandas df传输到db.sqlite3 - Transfer pandas df to db.sqlite3 using django models 如何删除并完全添加新的db.sqlite3到以pycharm编写的django项目中? - How to remove and add completly new db.sqlite3 to django project written in pycharm?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM