将开发 SQL Server 复制到拇指驱动器的最简单方法
我有一个小型 SQL 数据库,仅位于我的开发 PC 上。我想经常将其备份到拇指驱动器上。如果我能让它在检测到拇指驱动器时自动按计划执行,那就更好了。有什么好的方法可以做到这一点?
I have a small SQL database that is on my development PC only. I'd like to make frequent backup copies of it to a thumb drive. If I could have it do it automatically on a schedule when the thumb drive is detected, that'd be even better. What's a good way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我这样做是为了让数据库和其他文件夹在每次插入 USB 驱动器时自动同步到 USB 驱动器:
SyncMe.bat 内容(更新以反映您的路径和文件名):
This is what I did to get the database and other folders to automatically sync to my USB drive every time I plug it in:
SyncMe.bat contents (update to reflect your paths and file names):
我认为您无法让 SQL Server 为您完成这一切。我最终会编写一个使用 SMO 来执行操作的小控制台应用程序对我来说的工作:
I don't think you can get SQL Server to do this all for you. I'd end up writing a little console app that used SMO to do the work for me:
您可以做的是复制 .mdf 和 .ldf 文件,如果您没有更改任何设置,您应该能够在此处找到它们:
C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA
I不认为您可以在服务器运行时执行此操作,但您可以轻松地从 Management Studio 分离数据库(右键单击数据库..任务..分离)。然后您可以肯定地复制文件,首先压缩它们应该会在大小上产生很大的差异并且易于对它们进行版本控制。
相反,在 Management Studio 中,您可以选择数据库节点,然后单击 .. 附加数据库以再次附加它们。
这看起来像关于这个问题的一篇好文章。
问候格特-扬
What you can do is copy the .mdf and .ldf files, if you didn't change any settings you should be able to find them around here:
C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA
I don't think you can do that while the server is running, but you can detach a DB easiliy from Management Studio (right-click database .. tasks .. detach). Then you can copy the files for sure, zipping them first should make a lot of difference in size and easy to version them.
The other way around, in management studio you can select the databases node, and richtclick .. attach database to attach them again.
This seems like a good article on the matter.
Regards Gert-Jan