SQL*Server 備份策略

作者:chao_ping    時間:01-10-14 18:13

Off-topic: SQL*Server 備份策略

朋友請我幫忙,無奈我也不懂SQLServer。
如何制定一個比較完備的SQL Server7的備份策略。
將要做磁盤鏡像。
但是SQL Server本身肯定還是需要備份的。
能否那位兄弟有成熟的再用的備份策略:腳本/文檔share 小弟一份!
謝謝。
[email protected]


作者:yanwang    時間:01-10-15 02:10

If you just want to backup once, follow the precedure below.
1. Open SQL Server Enterprise Manager.
2. Click Microsoft SQL servers
3. Click + on the left side of SQL Server group
4. Click + on the left side of the SQL server that you are interesting
5. Click + on the left side of Databases folder
6. Find the database that you want backup, right mouse click on the database.
7. Highlight All Tasks-->Backup databases...
8. Mark radio button Database-complete for full backup
9. Under destination, click add, then select the directory that the backup file will go, or select the tape drive by click Backup Device radio button. Then click OK. Then OK again. The backup will start.

If you want to schedule backup, you need to create a Database Maintenance Plan. The steps 1-4 are the same.
5. Click + on the left side of Management folder.
6. Right mouse click on Database Maintenance Plans, then click New Maintenance plan...
7. Click next.
8. Select databases that you want to backup, I always select all databases.
9. Click next.
10. select Update statistics used by query optimizer, or nothing. I don't select the other two selection, click next.
11. select Check database integrity. click next.
12. Mark Backup the database as part of the maintenance plan. Select tape if you want to backup to tape, or disk. Under the schedule, click change, then you could select the time you want, then click OK. click next
13. Mark Create a subdirectory for each database. Select the time you want to Remove files older than ?? weeks. Click next.
14. Mark Backup the transanction log as part of the maintenance plan. Then select tape or disk. same as before. you can change the time. For production, backup the transanction log every two hours is a normal setting. For heavily used system, the time could be 30 min. Click next.
15. Same as before, mark Create a subdirectory for each database. Select the time you want to Remove files older than ?? weeks. Click next.
16. Select write report to file or send an e-mail to operators. I did not use mail. Click next.
17. To write the record, you may use the default setting, click next.
18. Then review the setting, if everything is OK, click finish, you are done. Then check the plan is executed or not next day.

For cold backup, one need to shutdown SQL Server, then use OS copy command to copy datafiles. Another way is to use detach and attach.

Please check books online. You can find almost all the answers there. Good luck!


作者:snowhite2000    時間:01-10-15 04:05

象yanwang說的一樣,做一次性backup還是create job or maintenance plan including backup plan for scheduling backup.

我是這樣做的:

1.create two maintenance plans, one for system database (master, model and msdb) full disk backup at 11pm from Mon to Sat. keep one week's backup copies on the hard disk. SQL SERVER job engin will delete old more than 7 days backup automatically.
another maintenance for user database. Full disk backup at 11:30pm Mon. to Sat. too. Log files, once an hour from 8am to 8pm from Mon. to Friday.

2. OS admin will use some other tool backup whole hard disk to tape. so I will have two backup copies. I have all database datafiles and logfiles, I can use store procedure sp_attach_db or sp_attach_single_file_db, I also can use resotre database commande to restore database from backup database file.

只有一點,我所知道的是SQL SERVER不需要做COLD backup. 這是一個先做過Oracle database的人的誤區。只要沒有用戶在線,沒有transaction,DBA不需要shutdown SQL SERVER. 而所謂的shutdown 只是stop mssqlserver 的services 而已。


作者:yanwang    時間:01-10-15 05:11

Thanks for sharing your strategy! Your backup method is perfect.


作者:kezizi    時間:01-10-15 07:17

on NT, to shutdown oracle is also to stop oracle service.


作者:guo    時間:01-10-15 09:11

還好,我做了3年的sqldba,手頭上有一些自己做的腳本
結構是這樣的:
dbbklist表用於存放數據備份信息如各個數據庫的備份目錄,完全備份和增量備份時間間隔
結構如下:
dbname sysname,--數據庫名
pastd tinyint,--自上次備份後的天數
fulld tinyint,--完全備份的時間間隔
diffd tinyint,--增量備份時間間隔
fdate varchar(10),--最近一次完全備份的時間
bpath varchar(255)--備份文件存放目錄

下面是備份過程:
create proc backupdb
as
declare
@errorno int,--用於檢查備份是否成功
@dbname sysname,
@pastd tinyint,
@fulld tinyint,
@diffd tinyint,
@fdate varchar(10),
@bpath varchar(255),
@today varchar(10)

declare dblist cursor
for select * from dbbklist--逐個數據庫進行處理

set @today=convert(varchar(10),getdate(),20)

open dblist
fetch next from dblist into @dbname,@pastd,@fulld,@diffd,@fdate,@bpath

while @@fetch_status =0
begin
if (@fdate is null) or (@fdate ='') begin--需要初始化備份.任務:進行備份,寫入當前日期至fdate中
exec ('BACKUP DATABASE '+@dbname+' TO DISK = '''+@bpath+@dbname+@today+'F.Bak'+
''' WITH INIT , NOUNLOAD , NAME ='''+@dbname+'在'+@today+'的完全備份'+
''', SKIP , restart, STATS = 10, NOFORMAT ')
update dbbklist set fdate=@today where current of dblist
print '數據庫'+@dbname+'完成第一次數據庫備份,本次完全備份日期爲:'+@today
end
else begin--如果不空,說明已經進行過備份.將@pastd與@fulld,@diffd進行比較
if @pastd>=@fulld begin --當@pastdate不小於@fulldate時,進行完全備份
exec ('BACKUP DATABASE '+@dbname+' TO DISK = '''+@bpath+@dbname+@today+'F.Bak'+
''' WITH INIT , NOUNLOAD , NAME ='''+@dbname+'在'+@today+'的完全備份'+
''', SKIP , restart, STATS = 10, NOFORMAT ')
--備份完成後將當前日期寫入到fdate中,將@pastdate置1,開始新一輪循環
update dbbklist set fdate=@today,pastd=1 where current of dblist
print '數據庫'+@dbname+'開始新一輪完全與差異備份.當前日期爲:'+@today
end
else begin--當@pastdate小於@fulldate時
if (@pastd>=@diffd) and (@pastd-@diffd*(@pastd/@diffd)=0) begin--當@pastdate不小於@diffd時,進行差異備份
exec ('BACKUP DATABASE '+@dbname+' TO DISK = '''+@bpath+@dbname+@fdate+'D.Bak'+
''' WITH INIT , NOUNLOAD ,DIFFERENTIAL , NAME ='''+@dbname+'在'+@today+
'的增量備份.上次完全備份時間:'+@fdate+''', SKIP , restart, STATS = 10, NOFORMAT ')
end
--備份完成後,將@pastdate加1,繼續循環
update dbbklist set pastd=@pastd+1 where current of dblist
print '一天又一天'
end
end
--處理下一條記錄
fetch next from dblist into @dbname,@pastd,@fulld,@diffd,@fdate,@bpath
end

close dblist
deallocate dblist

GO


具體使用上過程是:
使用job每天調用存儲過程backupdb,由該過程檢查是否需要進行備份以及何種備份,dblist記錄對個個數據庫的備份配置信息,可以使用標準insert ,update,delete進行編輯

這個過程在以前做sqldba時用過,後來轉到oracle就不用了,有些地方需要完善比如老備份文件的清除功能沒有做進去.


作者:chao_ping    時間:01-10-15 10:02

謝謝各位。
我用你們的方法試試看,有問題繼續提問。
謝謝啦

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章