SQL SERVER数据库还原Powershell [英] SQL SERVER DB Restore Powershell

查看:85
本文介绍了SQL SERVER数据库还原Powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近向我分配了一个任务,以创建一个脚本来还原SQL Server 2008 R2服务器上的多个数据库.要求使用Powershell..\
每日Backkups存储在共享位置(从该位置进行robocopy到SQL Server之一).数据文件和日志文件位于除C驱动器之外的预定义位置.

想开始编写执行多个数据库还原的方法,从备份头读取数据库名称,该名称与db backup命令的move and replace选项一起使用,并且最好在数据库还原失败时发送电子邮件.

代码项目上的脚本之一确实很好地还原了SQL Server数据库..我如何循环它?


在Advance中致谢

解决方案

如果您已经具有用于还原一个数据库文件的Powershell代码,那么您快完成了.只需执行Powershell命令以列出文件夹中的所有备份文件(无论它们在哪里).然后将这些文件名通过管道传递到您的还原脚本中,并用管道传递的值替换脚本中的硬编码文件名.

如果您没有备份脚本或不想查看其他脚本,那么这里是一个相当不错的脚本: http://www.sswug.org/articles/viewarticle.aspx?id=44909 [ ^ ]


谢谢.
我开发了用于每个循环的脚本,该脚本从预定义的位置中选择备份文件,验证备份,读取标头,对多个数据文件进行处理,并在还原失败时发送电子邮件.


Recently a task is assigned to me to create a script which restores mutiple databases on SQL Server 2008 R2 server. Powershell was asked to be used..\
The daily backkups are stored at share location from where robocopy is done to one of SQL Server. The data files and log files sit a predefined location on other than C drive.

Would like how to start writing that does the multiple db restore, reads the db name from backup header, which uses with move and replace option of db backup command and preferably also sends an email in event of db restore failure.

One of the script on code project does restore of SQL server db nicely.. how can i loop it?


Thanks in Advance

解决方案

If you already have the Powershell code to restore one database file, you are nearly done. Simply do a Powershell command to list all of the backup files in your folder (wherever they are). Then pipe those file names into your restore script and replace the hard-coded file name in the script with the piped-in value.

If you don''t have the backup script or wanted to look at another, here is a fairly good one: http://www.sswug.org/articles/viewarticle.aspx?id=44909[^]


Thanks.
I have developed the script using for each loop which picks the backup files from a pre defined location, verify backup, read header , does processing for multiple data files and sends an email when restore fails.


这篇关于SQL SERVER数据库还原Powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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