[英]Powershell SQL Server 2008 Database Backup Remotely
I am trying to backup a remote database on the LAN to a network shared drive. 我正在尝试将LAN上的远程数据库备份到网络共享驱动器。 I tested using the same approach using .NET and it did work but i am planning to use this PowerShell script withing out Jenkins Continuous Integration tool.
我使用相同的方法使用.NET测试它确实有效,但我打算使用这个PowerShell脚本,同时使用Jenkins持续集成工具。
$dbserver = "dbserver"
$location = "\\otherserver\Temp\"
$user = "user"
$pwd = "password"
$timestamp=((get-date).toString("yyyy_MM_dd_hh_mm"))
$file = $location + "jira_" + $timestamp + ".bak"
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null
$connection = New-Object "Microsoft.SqlServer.Management.Common.ServerConnection"
$connection.ServerInstance =$dbserver
$connection.LoginSecure = $false
$connection.Login = $user
$connection.Password = $pwd
$server = New-Object "Microsoft.SqlServer.Management.Smo.Server" $connection
$backup = New-Object "Microsoft.SqlServer.Management.Smo.backup"
$backup.Action = 'Database'
$device = New-Object ('Microsoft.SqlServer.Management.Smo.BackupDeviceItem') ($file, 'File')
#$device.DeviceType = 'File'
#$device.Name = $file
$backup.MediaDescription = "Disk"
$backup.Database= "jira"
$backup.Devices.Add($device)
$backup.SqlBackup
I don't get any exceptions but also I don't get any information that can help me troubleshoot my code. 我没有任何例外,但我也没有得到任何可以帮助我解决代码问题的信息。 Using all available throw, catch, try I can only get.
使用所有可用的throw,catch,尝试我只能得到。
MemberType : Method
OverloadDefinitions : {System.Void SqlBackup(Microsoft.SqlServer.Management.Smo.Server srv)}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : System.Void SqlBackup(Microsoft.SqlServer.Management.Smo.Server srv)
Name : SqlBackup
IsInstance : True
SqlBackup is a method. SqlBackup是一种方法。 When you call a method you need to include opening and closing parenthesis:
调用方法时,需要包括左括号和右括号:
$backup.sqlbackup($server)
Omitting the parens will output the method signature instead of calling the method. 省略parens将输出方法签名而不是调用方法。 Omitting the method signature is not an error hence no error.
省略方法签名不是错误,因此没有错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.