每小时自动恢复数据库的最佳方法
我有一个演示网站,任何人都可以登录并测试管理界面。
每小时我都会刷新 SQL 2008 数据库中的所有数据并将其从原始状态恢复。
Red Gate Software 为此提供了一些很棒的工具,但它们目前超出了我的预算。
我可以简单地制作数据库数据文件的备份副本,然后使用 ac# 控制台应用程序删除它并复制原始文件吗?然后我可以有一个 Windows 计划任务每小时运行 .exe。
它简单且免费...这行得通吗?
我正在使用 SQL Server 2008 R2 Web 版
我知道 Red Gate Software 在技术上更好,因为我可以将其设置为分析数据库并仅更新已更改的记录,而我上面的方法就像“大锤”。
I have a demo site where anyone can login and test a management interface.
Every hour I would like to flush all the data in the SQL 2008 Database and restore it from the original.
Red Gate Software has some awesome tools for this, however they are beyond my budget right now.
Could I simply make a backup copy of the database's data file, then have a c# console app that deletes it and copies over the original. Then I can have a windows schedule task to run the .exe every hour.
It's simple and free... would this work?
I'm using SQL Server 2008 R2 Web edition
I understand that Red Gate Software is technically better because I can set it to analyze the db and only update the records that were altered, and the approach I have above is like a "sledge hammer".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您可以这样做,只需记住在恢复之前将数据库置于单用户模式,否则您的恢复将失败
示例脚本
Yes, you could do it like that, just remember to put the DB in single user mode before restoring it otherwise your restore will fail
example script
可以使用 SQL 编写脚本,并将其安排为服务器上的作业,每小时执行一次。我认为,既然您有一个原始的备份副本,那么您所需要做的就是使数据库脱机,从备份中恢复,然后使数据库重新联机。所有这些都可以编写脚本。您需要脚本吗?
This can be scripted using SQL and scheduled as a job on the server to execute once an hour. Since you have a backup copy, I assume, that is pristine, then all you need to do is take the database offline, restore from the backup, bring the database back online. All of this can be scripted. Do you need the scripts?
您还可以分离数据库,覆盖模板中的数据和日志文件(之前分离),然后重新附加。
You could also detach the database, overwrite the data and log files from your template (previously detached) and then re-attach.