Sql server 备份数据库的批处理文件不工作
我正在尝试从批处理文件备份数据库,但它没有执行。当我从命令提示符手动执行时,它甚至不作为管理员工作。我没有得到任何错误,它只是不执行Sql server 备份数据库的批处理文件不工作,sql-server,batch-file,command-line,Sql Server,Batch File,Command Line,我正在尝试从批处理文件备份数据库,但它没有执行。当我从命令提示符手动执行时,它甚至不作为管理员工作。我没有得到任何错误,它只是不执行 "C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\SQLCMD.exe" -S "(localdb)\mssqllocaldb" –E -Q "EXEC sp_BackupDatabases @backupLocation='C:\SQLBackups\', @
"C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\SQLCMD.exe" -S "(localdb)\mssqllocaldb" –E -Q "EXEC sp_BackupDatabases @backupLocation='C:\SQLBackups\', @backupType='F'"
与
-S
和-Q
不同,在-E
中有一个短划线字符而不是连字符减号
powershell中显示的差异:
PS D:\PShell> '–-' | Get-CharInfo
Char CodePoint Category Description
---- --------- -------- -----------
– U+2013 DashPunctuation En Dash
- U+002D DashPunctuation Hyphen-Minus
令人惊讶的是,在打开的cmd
窗口中,Copy&Paste会无声地将短划线字符转换为连字符减号,并给出以下输出:
==> powershell -c "'--' | Get-CharInfo"
Char CodePoint Category Description
---- --------- -------- -----------
- U+002D DashPunctuation Hyphen-Minus
- U+002D DashPunctuation Hyphen-Minus
为完整起见,自定义Get-CharInfo
cmdlet定义如下:
<#
_get-CharInfo_1.1.ps1
Origin by: http://poshcode.org/5234
sorry, the above link is not available; last time checked 2018-05-07
Improved by: https://stackoverflow.com/users/3439404/josefz
Use this like this: "ábč",([char]'x'),0xBF | Get-CharInfo
Activate dot-sourced like this (apply a real path instead of .\):
. .\_get-CharInfo_1.1.ps1
#>
Set-StrictMode -Version latest
Add-Type -Name UName -Namespace Microsofts.CharMap -MemberDefinition $(
switch ("$([System.Environment]::SystemDirectory -replace
'\\', '\\')\\getuname.dll") {
{Test-Path -LiteralPath $_ -PathType Leaf} {@"
[DllImport("${_}", ExactSpelling=true, SetLastError=true)]
private static extern int GetUName(ushort wCharCode,
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder buf);
public static string Get(char ch) {
var sb = new System.Text.StringBuilder(300);
UName.GetUName(ch, sb);
return sb.ToString();
}
"@
}
default {'public static string Get(char ch) { return "???"; }'}
})
function Get-CharInfo {
[CmdletBinding()]
[OutputType([System.Management.Automation.PSCustomObject],[System.Array])]
param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
$InputObject
)
begin {
function out {
param(
[Parameter(Position=0, Mandatory=$true )] $ch,
[Parameter(Position=1, Mandatory=$false)]$nil=''
)
if (0 -le $ch -and 0xFFFF -ge $ch) {
[pscustomobject]@{
Char = [char]$ch
CodePoint = 'U+{0:X4}' -f $ch
Category = [System.Globalization.CharUnicodeInfo]::GetUnicodeCategory($ch)
Description = [Microsofts.CharMap.UName]::Get($ch)
}
} elseif (0 -le $ch -and 0x10FFFF -ge $ch) {
$s = [char]::ConvertFromUtf32($ch)
[pscustomobject]@{
Char = $s
CodePoint = 'U+{0:X}' -f $ch
Category = [System.Globalization.CharUnicodeInfo]::GetUnicodeCategory($s, 0)
Description = '???' + $nil
}
} else {
Write-Warning ('Character U+{0:X} is out of range' -f $ch)
}
}
}
process {
if ($PSBoundParameters['Verbose']) {
Write-Warning "InputObject type = $($InputObject.GetType().Name)"}
if ($null -cne ($InputObject -as [char])) {
#Write-Verbose "A $([char]$InputObject) InputObject character"
out $([int][char]$InputObject) ''
} elseif ($InputObject -isnot [string] -and $null -cne ($InputObject -as [int])) {
#Write-Verbose "B $InputObject InputObject"
out $([int]$InputObject) ''
} else {
$InputObject = [string]$InputObject
#Write-Verbose "C $InputObject InputObject.Length $($InputObject.Length)"
for ($i = 0; $i -lt $InputObject.Length; ++$i) {
if ( [char]::IsHighSurrogate($InputObject[$i]) -and
(1+$i) -lt $InputObject.Length -and
[char]::IsLowSurrogate($InputObject[$i+1])) {
$aux = ' 0x{0:x4},0x{1:x4}' -f [int]$InputObject[$i],
[int]$InputObject[$i+1]
Write-Verbose "surrogate pair $aux at position $i"
out $([char]::ConvertToUtf32($InputObject[$i], $InputObject[1+$i])) $aux
$i++
} else {
out $([int][char]$InputObject[$i]) ''
}
}
}
}
}
设置StrictMode-最新版本
添加Type-Name UName-Namespace Microsofts.CharMap-MemberDefinition$(
开关(“$”([System.Environment]::SystemDirectory-replace
“\\”、“\\”)\\getuname.dll){
{Test Path-LiteralPath$\路径类型Leaf}{@”
[DllImport(“${{}”,ExactSpelling=true,SetLastError=true)]
私有静态外部文件(ushort wCharCode,
[Marshallas(UnmanagedType.LPWStr)]System.Text.StringBuilder buf);
公共静态字符串Get(char ch){
var sb=新的System.Text.StringBuilder(300);
UName.GetUName(ch,sb);
使某人返回字符串();
}
"@
}
默认{'publicstaticstringget(charch){return???“;}'}
})
函数Get CharInfo{
[CmdletBinding()]
[OutputType([System.Management.Automation.PSCustomObject],[System.Array])]
param(
[参数(位置=0,必需=$true,ValueFromPipeline=$true)]
$InputObject
)
开始{
发挥作用{
param(
[参数(位置=0,强制=true)]$ch,
[参数(位置=1,强制=false)]$nil=''
)
if(0-le$ch-和0xFFFF-ge$ch){
[pscustomobject]@{
Char=[Char]$ch
代码点='U+{0:X4}'-f$ch
Category=[System.Globalization.CharUnicodeInfo]::getunicodegory($ch)
Description=[Microsofts.CharMap.UName]::Get($ch)
}
}elseif(0-le$ch-和0x10FFFF-ge$ch){
$s=[char]::ConvertFromUtf32($ch)
[pscustomobject]@{
Char=$s
代码点='U+{0:X}'-f$ch
Category=[System.Globalization.CharUnicodeInfo]::getUnicodeCegory($s,0)
Description='???'+$nil
}
}否则{
写入警告('U+{0:X}字符超出范围'-f$ch)
}
}
}
过程{
if($PSBoundParameters['Verbose'])){
写入警告“InputObject类型=$($InputObject.GetType().Name)”}
if($null-cne($InputObject-as[char])){
#详细写入“一个$([char]$InputObject)InputObject字符”
out$([int][char]$InputObject)'
}elseif($InputObject-isnot[string]-和$null-cne($InputObject-as[int])){
#详细编写“B$InputObject InputObject”
out$([int]$InputObject)'
}否则{
$InputObject=[string]$InputObject
#详细写入“C$InputObject InputObject.Length$($InputObject.Length)”
对于($i=0;$i-lt$InputObject.Length;+$i){
if([char]::ishighsrogate($InputObject[$i])-和
(1+$i)-lt$InputObject.Length-和
[char]::IsLowSurrogate($InputObject[$i+1])){
$aux='0x{0:x4},0x{1:x4}'-f[int]$InputObject[$i],
[int]$InputObject[$i+1]
详细写入“位置$i处的代理项对$aux”
out$([char]::ConvertToUtf32($InputObject[$i],$InputObject[1+$i]))$aux
$i++
}否则{
out$([int][char]$InputObject[$i])”
}
}
}
}
}