日期:2014-05-18  浏览次数:20803 次

如何实现每天增量备份,周末完全备份的维护计划
谢谢

------解决方案--------------------
数据库维护计划1:1-6增量备份
数据库维护计划2:7完全备份

------解决方案--------------------
数据库维护计划里面可以设计


增量备份就是差异备份
------解决方案--------------------
分別建兩個.bat文件,一個作差异备份
一個作完全备份

再在系統裡設定排程計劃
下面是一個完全備份例子:
backup.bat
-----------------------
F:
cd \
cd sql

"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql " -U sa -P turbo -S Servername -i backup.sql

set WEEK=%errorlevel%
:ZIP
"C:\Program Files\WinRAR\Rar.exe " a e:\test\smepos%WEEK% e:\test\aa.dat
del e:\test\aa.dat
pause
:END
echo DONE!

backup.sql
----------------------------
backup database XXXXX to disk= 'e:\test\test.dat '
GO
exit(select DatePart(weekday, getdate())-1)

其中的DB名,路徑等自己改一下就行了
------解决方案--------------------
差異備份可參考以下例子

backupall.bat
---------------------
E:
cd \
cd test

"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql " -U sa -P turbo -S Servername -i backupall.sql
set WEEK=%errorlevel%

if "%WEEK% "== "0 " goto ZIP_FULL
:ZIP_DIFF
del e:\test\db_diff%WEEK%.rar /q
del e:\test\sys_full%WEEK%.rar /q
"C:\Program Files\WinRAR\Rar.exe " a e:\test\db_diff%WEEK% e:\test\*.diff
"C:\Program Files\WinRAR\Rar.exe " a e:\test\sys_full%WEEK% e:\test\*.full
del e:\test\*.diff
del e:\test\*.full
goto END

:ZIP_FULL
del e:\test\db_full%WEEK%.rar /q
"C:\Program Files\WinRAR\Rar.exe " a e:\test\db_full%WEEK% e:\test\*.full
del e:\test\*.full
goto END
:END
copy e:\test\db_diff%WEEK%.rar h:\test
copy e:\test\sys_full%WEEK%.rar h:\test
copy e:\test\db_full%WEEK%.rar h:\test
echo DONE!


------------------------------------
backupall.sql
---------------------------
declare @file varchar(100)
declare @backup_path varchar(30)
declare @week char(1)
declare @ext varchar(5)

set @backup_path= 'e:\test\ '
select @week=DatePart(weekday, getdate())-1

-- 星期日才做完整備份, 其他只做差異性備份
if @week = 0
set @ext = '.full '
else
set @ext = '.diff '

declare cursor1 cursor for
select name from master.dbo.SysDatabases
declare @db_name varchar(20)
declare @cmd varchar(8000)
--set @cmd = ' '

open cursor1
fetch cursor1 into @db_name
while(@@FETCH_STATUS = 0) begin
set @file =@backup_path + @db_name + @ext
if @week = 0 -- 星期天完整備份
backup database @db_name to disk=@file with INIT
else
backup database @db_name to disk=@file with INIT,differential

fetch cursor1 into @db_name
end

close cursor1
deallocate cursor1

set @db_name = 'msdb '
set @file =@backup_path + @db_name + '.full '
backup database @db_name to disk=@file with INIT

set @db_name = 'master '
set @file =@backup_path + @db_name + '.full '
backup database @db_name to disk=@file with INIT

-- 傳回星期幾
exit(select DatePart(weekday, getdate())-1)