微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我自己的项目的sqlserver 2008 r2 express的自动备份的脚本

参见上一篇文章



backup_database.bat


C:
cd C:\Program Files\Microsoft sql Server\100\Tools\Binn
sqlCMD -S .\sqlexpress -U sa -P Dayawan123  -i J:\Database_Backup\backup.sql



backup.sql


GO

DECLARE   
@backupTime VARCHAR(20)  
DECLARE   
@fileName VARCHAR(1000)    
SELECT  
 @backupTime=(CONVERT(VARCHAR(8),GETDATE(),112) +REPLACE(CONVERT(VARCHAR(5),114),':',''))    
SELECT  
 @fileName='J:\Database_Backup\DB_'+@backupTime+'.bak'  
backup database SafetyValve to disk=@fileName  
GO 


然后是创建的计划任务

safetyValve backup.xml


<?xml version="1.0" encoding="UTF-16"?> <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">   <RegistrationInfo>     <Date>2015-05-11T16:50:27.0939616</Date>     <Author>WINDOWS-XCBQ5Y7\Administrator</Author>     <Description>backup every 2 am</Description>   </RegistrationInfo>   <Triggers>     <CalendarTrigger>       <StartBoundary>2015-05-11T02:00:00</StartBoundary>       <Enabled>true</Enabled>       <ScheduleByDay>         <DaysInterval>1</DaysInterval>       </ScheduleByDay>     </CalendarTrigger>   </Triggers>   <Principals>     <Principal id="Author">       <UserId>WINDOWS-XCBQ5Y7\Administrator</UserId>       <logonType>Interactivetoken</logonType>       <RunLevel>LeastPrivilege</RunLevel>     </Principal>   </Principals>   <Settings>     <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>     <disallowStartIfOnBatteries>true</disallowStartIfOnBatteries>     <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>     <AllowHardTerminate>true</AllowHardTerminate>     <StartWhenAvailable>false</StartWhenAvailable>     <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>     <IdleSettings>       <Duration>PT10M</Duration>       <WaitTimeout>PT1H</WaitTimeout>       <StopOnIdleEnd>true</StopOnIdleEnd>       <RestartOnIdle>false</RestartOnIdle>     </IdleSettings>     <AllowStartondemand>true</AllowStartondemand>     <Enabled>true</Enabled>     <Hidden>false</Hidden>     <RunOnlyIfIdle>false</RunOnlyIfIdle>     <WaketoRun>false</WaketoRun>     <ExecutionTimeLimit>P3D</ExecutionTimeLimit>     <Priority>7</Priority>   </Settings>   <Actions Context="Author">     <Exec>       <Command>J:\Database_Backup\backup_database.bat</Command>     </Exec>   </Actions> </Task>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐