那么,在此期间我拼凑在一起的另一种解决方案。也许这将是使用的人的..
[Run.cmd] --May需要改变
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -noninteractive -command "C:\Scripts\RunBackup.ps1"
[RunBackup.ps1] --out-文件没有预期的效果PowerShell的路径,也许有人可以弄清楚为什么?
C:\Scripts\SqlBackup.ps1 | Out-File "C:\Scripts\log.txt"
C:\Scripts\SVNBackup.ps1 | Out-File "C:\Scripts\log.txt"
C:\Scripts\Zip.ps1 | Out-File "C:\Scripts\log.txt"
[SqlBackup.ps1] - 您可能需要修改其SMO集加载,这取决于你 版本的SQL Server。不要忘记设置$ instance和$ bkdir。
#http://www.mssqltips.com/tip.asp?tip=1862&home
$instance = ".\SQLEXPRESS"
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SMO.dll") | out-null
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SMOExtended.dll") | out-null
$s = new-object ("Microsoft.SqlServer.Management.Smo.Server") $instance
$bkdir = "c:\Backups" #We define the folder path as a variable
$dbs = $s.Databases
foreach ($db in $dbs)
{
if($db.Name -ne "tempdb") #We don't want to backup the tempdb database
{
$dbname = $db.Name
$dt = get-date -format yyyyMMddHHmm #We use this to create a file name based on the timestamp
$dbBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup")
$dbBackup.Action = "Database"
$dbBackup.Database = $dbname
$dbBackup.Devices.AddDevice($bkdir + "\" + $dbname + "_db_" + $dt + ".bak", "File")
$dbBackup.SqlBackup($s)
}
if($db.RecoveryModel -ne 3) #Don't issue Log backups for DBs with RecoveryModel=3 or SIMPLE
{
$dbname = $db.Name
$dt = get-date -format yyyyMMddHHmm #Create a file name based on the timestamp
$dbBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup")
$dbBackup.Action = "Log"
$dbBackup.Database = $dbname
$dbBackup.Devices.AddDevice($bkdir + "\" + $dbname + "_log_" + $dt + ".trn", "File")
$dbBackup.SqlBackup($s)
}
}
[SVNBackup.ps1] --modify回购和备份路径
#set alias to svnadmin exe
set-alias svnadmin "C:\Program Files (x86)\CollabNet Subversion Server\svnadmin.exe"
#create dump
cmd.exe /c svnadmin dump "C:\Repo" `> "C:\Backups\svn.dmp"
#remove alias
remove-item alias:svnadmin
[Zip.ps1] --Need有7zip的安装,如果需要的话
#set alias to command line version of 7zip
set-alias sevenz "c:\program files\7-zip\7z.exe"
#Backups location
cd 'C:\Backups'
#rar the contents of the directory
$dt = get-date -format yyyyMMddHHmm #We use this to create a file name based on the timestamp
$outputFileName = "SQLSVNBackup$dt.7z"
$exclude1 = "-x!*.rar"
$exclude2 = "-x!*.7z"
sevenz a -t7z "$outputFileName" *.* "$exclude1" "$exclude2"
#find all .bak files in the immediate directory
dir '*.bak' | foreach-object{
#remove the bak file
remove-item $_.name
}
#find all .dmp files in the immediate directory
dir '*.dmp' | foreach-object{
#remove the dmp file
remove-item $_.name
}
#find all .trn files in the immediate directory
dir '*.trn' | foreach-object{
#remove the trn file
remove-item $_.name
}
#remove 7zip alias
remove-item alias:sevenz
修改7z.exe路径
我以前GoodSync备份到WebDAV和计划两个任务运行.cmd文件,然后同步/备份异地。
感谢您的信息! – bszom 2010-05-11 09:09:51
+1用于输出重定向的反向提示。 – 2010-07-07 11:20:28