夏日部落客BloggerAds《2008‧夏》

2008年4月8日 星期二

SQL Server 2005 Backup 介紹

最近對SQL Server的備份有些需求: 希望能夠定期備份資料庫,且希望備分檔名是XX_yyyyMMdd.bak 的格式,這樣輩分的檔案就會對應備份的日期,不會被抹寫掉,此外還要能夠備分到另一台主機上。

我的平台是SQL 2005,備份的方式其實很簡單,首先先簡易說明SQL提供的備份方式,有下列四種:

SQL Server provides four different methods for backing up your database:

  • A full backup makes a complete backup of your database. You will almost always need to start your backup strategy with a full backup of your database.
  • A file backup is useful when your database is so large that a full backup would take too long.
  • A transaction log backup creates a copy of all changes made to the database that are currently stored in the transaction log.
  • A differential backup stores all changes that have occurred to the database since the last full backup.

我這邊僅介紹第一種full backup,這種方式不適合資料量很大的資料庫,操作方式如下。

image

針對要備份的資料庫,點擊滑鼠右鍵,會跳出選單,選擇紅框部份,進入畫面後,選擇下圖紅框部份

image

接著,就會進入編輯備份的工作,重點在於Steps的選項中,必須新增新工作(實際要備份的工作),

image

這邊可以編輯Script做進階的動作,而我備份的檔名正好需要用到此功能,以下是我備份到本機的方式。這邊有一個小細節要注意,N這個參數代表是本機磁碟的意思,所以一定要有的,此外單引號要注意,不然也會有錯誤。

image

下圖是我備份到網路磁碟的方式。

image

接著設定排程都有介面可以設定,這邊也不再贅述。這樣就簡易的設定可以完成一個簡單的備份工作。

此外,設定完成後,實際執行此工作是由SQL Server Agent完成的,可以觀察到Jobs多了一項剛剛新增的工作,如果想測試剛才的設定是否可以正確執行,可以選擇Start Job就會執行此項目的設定,若有錯誤則可以觀看歷史紀錄檔,也可以以進入屬性進行修改。

image 

參考連結:

http://www.devx.com/getHelpOn/10MinuteSolution/16507/1954

http://blog.sjzj.com.cn/article.asp?id=689

http://www.sqlteam.com/tag/sql-server-backup-restore

0 意見: