备份 Rails 应用程序数据的最佳方法是什么?
我需要为我的 Rails 应用程序创建一个备份系统,但这必须有点特别:它不必备份单个文件或文件夹中的所有数据库信息和文件,但它有备份每个用户的数据库信息和附件文件。我的意思是,每个备份都应该能够为一个用户重新生成所有信息和文件。
我的问题是: 这可能吗?最好的方法是什么?而且,如果这是不可能的或者根本就是一个坏主意,为什么呢?
注意:数据库是MySQL数据库。 注2:我使用Paperclip
来进行用户上传。
I need to make a backup system for my rails app but this has to be a little special: It doesn't have to back up all the database info and files in a single file or folder but it has to back up the database info and attachment files per user. I mean, every one of this backups should be able to regenerate all the information and files for one single user.
My questions are:
Is this possible? What's the best way to do it? And, if it's impossible or a bad idea at all, why is it?
Note: The database is a MySQL one.
Note2: I used Paperclip
for the users uploads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜你有一个应用程序可以在用户单击某些内容时备份数据,对吧?我正在考虑获取连接到用户的所有信息(取决于您如何创建用户模型,所以也许您应该有一个 get_all_info 方法),然后以 sql 格式将其写到一个文件中,并将其另存为 .sql。 (使用 File.new 或 Logger.new)
Im guessing you have an app that backs up data, when a user clicks on something right? I'm thinking get all the info connected to the user(depends on how you did your user model, so maybe you should have a get_all_info method) then write it out in sql format to a file, which you save as .sql. (either using File.new or Logger.new)
我会将整个用户对象和相关对象转储到单个 xml 文件转储中。当您创建 XML 时,取出所有文件并将 XML + 所有文件写入一个目录,然后压缩它们。
我认为肯定有使用案例来拥有这样的功能,但一定要让它在后台进程中运行,并且仅在需要时运行,以免使网络服务器陷入困境。看看 http://github.com/tobi/delayed_job 或 http://github.com/defunkt/resque。
I would dump the entire user object and related objects into a single xml file dump. As you go through the creation of the XML grab out all the files and write the XML + all files into one directory, then compress them.
I think there are definitely use cases to have a feature like this, but be sure to have it run in a background process and only when needed in order to not bog down the web server. Take a look at http://github.com/tobi/delayed_job or http://github.com/defunkt/resque.