部署到OpenShift后如何防止SQLite数据库还原? [英] How to preserve a SQLite database from being reverted after deploying to OpenShift?

查看:74
本文介绍了部署到OpenShift后如何防止SQLite数据库还原?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Python Twisted应用程序移植到OpenShift,该应用程序将其数据存储到SQLite数据库.将数据库文件放入git repo data/目录之后(第一次部署期间),我没有遇到任何问题,但是只是在第二次部署时重置了数据库.

I ported a Python Twisted application to OpenShift, which stores its data to a SQLite database. After putting database file to the git repo data/ directory (during the first deploy) I had no issues, but the database was simply resetted at the second deploy.

我正在寻找一种适当的解决方案来解决这种奇怪的行为(考虑到数据库正在版本控制中),然后我发现了

I searched for a proper solution to this weird behavior (considering that the database was under versioning) and then I found the answer in the OpenShift Knowledge Base:

此问题的简短解决方案是将您的SQLite数据库从git存储库上一级存储在数据"目录中.

现在我的问题是将数据库移到该目录时会发生什么?我是否要移动或复制数据目录的内容?而且这些数据将在部署到部署之间保留下来?

Now my question is what happens when I move the database to this directory? Have I to move or copy the data directory's content? And this data will be preserver from deploy to deploy?

我试图将数据库从repo/data移到data/目录,但是应用程序无法访问该上级目录.我正在寻找解决此问题的最佳方法.

I tried to move the database from repo/data to data/ directory but the application cannot access this upper level directory. I'm looking for the best solution to this problem.

推荐答案

我已经找到了将应用程序数据分为两类的解决方案:

I've found a solution by dividing my application data into two categories:

  • 状态数据
  • 动态数据

我将状态信息留在repo/data目录中,并将更改的数据永久移动到上层data/目录中.进行此更改,我可以在git repo中通过以下方式将stateful_data维持在版本控制下:

I left the stateful information in the repo/data directory and I moved permanently the changing data to the upper level data/ directory. Making this change I am able to maintain the stateful_data under version control in my git repo accessing them through:

 __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
 static_data_folder = __location__ + '/data/'

然后将动态生成的数据移到不受版本控制的$OPENSHIFT_DATA_DIR中,该$OPENSHIFT_DATA_DIR对应于我的app-root的上级目录.我在单例配置模块中更改了吸气剂,以返回此可变数据文件夹:

The dynamically generated data is then moved to $OPENSHIFT_DATA_DIR which is NOT under version control and corresponds to the upper level directory of my app-root. I changed my getter in my singleton Configuration module to return this mutable data folder:

self.mutable_data_path = os.environ['OPENSHIFT_DATA_DIR'] + "mutable_data_subdir/"

我现在正在测试此配置,但它看起来像是一种魅力.

I'm testing this configuration right now but it seems to work like a charm.

这篇关于部署到OpenShift后如何防止SQLite数据库还原?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆