每小时自动恢复数据库的最佳方法

发布于 2024-09-03 06:38:46 字数 412 浏览 6 评论 0原文

我有一个演示网站,任何人都可以登录并测试管理界面。

每小时我都会刷新 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

叫思念不要吵 2024-09-10 06:38:47

<块引用>

简单又免费......这行得通吗?

是的,您可以这样做,只需记住在恢复之前将数据库置于单用户模式,否则您的恢复将失败

示例脚本

USE master
GO

ALTER DATABASE YourDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO



RESTORE DATABASE YourDB FROM DISK=N'D:\Backup\Pristine.BAK' WITH  FILE = 1,  
NOUNLOAD,  REPLACE,  STATS = 10
GO

ALTER DATABASE YourDB SET MULTI_USER
GO

It's simple and free... would this work?

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

USE master
GO

ALTER DATABASE YourDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO



RESTORE DATABASE YourDB FROM DISK=N'D:\Backup\Pristine.BAK' WITH  FILE = 1,  
NOUNLOAD,  REPLACE,  STATS = 10
GO

ALTER DATABASE YourDB SET MULTI_USER
GO
怂人 2024-09-10 06:38:47

可以使用 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?

美男兮 2024-09-10 06:38:47

您还可以分离数据库,覆盖模板中的数据和日志文件(之前分离),然后重新附加。

You could also detach the database, overwrite the data and log files from your template (previously detached) and then re-attach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文