您好,登錄后才能下訂單哦!
all-sql-about_bak_restore(一):
#完全備份
backup database record to disk = 'E:\backup\record.bak' with retaindays=9,format,init,compression;
#差異備份
backup database record to disk='E:\backup\record.bak' with differential,retaindays=9,noformat,noinit,compression;
#日志備份
backup log record to disk = 'E:\backup\record.bak' with retaindays=9,compression;
在[還原]運行前,要把數據庫[多用戶]模式改成[單用戶]模式:
右鍵數據庫“屬性”-“選項”-“狀態”-“限制訪問”-把“MULTI_USER”改成“SINGLE_USER”確定,
執行以下命令:
#備份結尾日志(做數據庫完全恢復之前使用,使數據庫處于還原狀態)
use master;backup log record to disk = 'E:\backup\log.bak' with norecovery,format,init,compression;
#查看備份介質中的備份信息
restore headeronly from disk='E:\backup\record.bak';
#列出備份集中包含的文件信息
restore filelistonly from disk='E:\backup\record.bak';
#逐個恢復備份集,恢復數據庫到指定時間點
restore database test from disk ='E:\backup\record.bak' with file=1,norecovery;
restore database test from disk ='E:\backup\record.bak' with file=2,norecovery,stopat='2017-01-12 05:39:31';
restore log test from disk ='E:\backup\record.bak' with file=3,norecovery,stopat='2017-01-12 05:39:31';
restore database record with recovery;
#備份結尾日志(做數據庫完全恢復之前使用,使數據庫處于還原狀態)
backup log record to disk = 'E:\backup\log.bak' with norecovery,format,init,compression;
--清空備份記錄
use msdb;
#清空指定時間點之前的備份記錄
exec sp_delete_backuphistory '2016-1-11';
#清空指定數據庫的備份記錄
exec sp_delete_database_backuphistory 'TEST';
all-sql-about_bak_restore(二):
#完全備份
backup database record to disk = 'E:\backup\record.bak' with retaindays=9,format,init,compression;
#差異備份
backup database record to disk='E:\backup\record.bak' with differential,retaindays=9,noformat,noinit,compression;
#日志備份
backup log record to disk = 'E:\backup\record.bak' with retaindays=9,compression;
在[還原]運行前,要把數據庫[多用戶]模式改成[單用戶]模式:
右鍵數據庫“屬性”-“選項”-“狀態”-“限制訪問”-把“MULTI_USER”改成“SINGLE_USER”確定,
執行以下命令:
#備份結尾日志(做數據庫完全恢復之前使用,使數據庫處于還原狀態)
use master;backup log record to disk = 'E:\backup\log.bak' with norecovery,format,init,compression;
#查看備份介質中的備份信息
restore headeronly from disk='E:\backup\record.bak';
#列出備份集中包含的文件信息
restore filelistonly from disk='E:\backup\record.bak';
#逐個恢復備份集,恢復數據庫到指定時間點
restore database test from disk ='E:\backup\record.bak' with file=1,norecovery;
restore database test from disk ='E:\backup\record.bak' with file=2,norecovery,stopat='2017-01-12 05:39:31';
restore log test from disk ='E:\backup\record.bak' with file=3,norecovery,stopat='2017-01-12 05:39:31';
restore database record with recovery;
#備份結尾日志(做數據庫完全恢復之前使用,使數據庫處于還原狀態)
backup log record to disk = 'E:\backup\log.bak' with norecovery,format,init,compression;
--清空備份記錄
use msdb;
#清空指定時間點之前的備份記錄
exec sp_delete_backuphistory '2016-1-11';
#清空指定數據庫的備份記錄
exec sp_delete_database_backuphistory 'TEST';
all-sql-about_bak_restore(三):
BACKUP DATABASE [timeRecord] TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.FANTASY\MSSQL\Backup\timeRecord.bak' WITH RETAINDAYS = 9, NOFORMAT, NOINIT, NAME = N'timeRecord-完整 數據庫 備份', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10, CHECKSUM
GO
BACKUP DATABASE [timeRecord] TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.FANTASY\MSSQL\Backup\timeRecord_diff.bak' WITH DIFFERENTIAL , RETAINDAYS = 9, NOFORMAT, NOINIT, NAME = N'timeRecord-差異 數據庫 備份', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10
GO
BACKUP LOG [timeRecord] TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL12.FANTASY\MSSQL\Backup\timeRecord_log.bak' WITH DESCRIPTION = '日志備份', RETAINDAYS = 7, FORMAT, INIT, NAME = 'timeRecord-日志備份', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10
GO
C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup
============================
BACKUP DATABASE [timeRecord] TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.FANTASY\MSSQL\Backup\timeRecord_diff.bak'
WITH RETAINDAYS = 9, NOFORMAT, NOINIT, COMPRESSION, DIFFERENTIAL;
GO
========================
#完全備份
backup database record to disk = 'E:\backup\record.bak' with retaindays=9,format,init,compression;
#差異備份
backup database record to disk='E:\backup\record.bak' with differential,retaindays=9,noformat,noinit,compression;
#日志備份
backup log record to disk = 'E:\backup\record.bak' with retaindays=9,compression;
#查看備份介質中的備份信息
restore headeronly from disk='E:\backup\record.bak';
#列出備份集中包含的文件信息
restore filelistonly from disk='E:\backup\record.bak';
=========================================
12號:
backup database zhaotest to disk = 'C:\mssql\backup\zhaotest.all.1.bak'
with retaindays=9,format,init,compression;
backup database zhaotest to disk='C:\mssql\backup\zhaotest.all.2.bak'
with differential,retaindays=9,noformat,noinit,compression;
backup log zhaotest to disk = 'C:\mssql\backup\zhaotest.all.3.bak'
with retaindays=9,compression;
======================================================
backup database zhaotest to disk = 'C:\mssql\backup\zhaotest.bak'
with retaindays=9,format,init,compression;
backup database zhaotest to disk='C:\mssql\backup\zhaotest.all.2.bak'
with differential,retaindays=9,noformat,noinit,compression;
backup log zhaotest to disk = 'C:\mssql\backup\zhaotest.all.4.bak'
with retaindays=9,compression;
restore database zhaotest from disk= 'C:\mssql\backup\zhaotest.all.3.bak'
with file=1,norecovery;
restore database zhaotest from disk='C:\MSSQL\Backup\zhaotest.all.2.bak'
with file=2,norecovery,stopat='2017-01-12 12:23:31';
restore log zhaotest from disk='C:\MSSQL\Backup\zhaotest.all.3.bak'
with file=3,norecovery,stopat='2017-01-12 19:23:21';
restore database zhaotest with recovery;
all-sql-about_bak_restore(四):
實驗一 SQLserver完全備份,差異備份,日志備份并且恢復到指定的時間點
示例:
備份(要求在每次備份前,都要向數據庫里更新數據)
恢復到指定時間點
要求,把操作的步驟截圖,貼到下面(至少要含有備份成功,恢復成功的步驟),如果恢復遇到數據庫被占用的問題,請參考附錄進行解決
附錄:
還原sql server數據庫遇到如下問題
該問題主要是你在還原的時候還有其他進程連在上面,導致無法獲得獨占造成的。
解決思路:
步驟
USE Master
ALTER DATABASE 數據庫名稱 SET OFFLINE WITH ROLLBACK IMMEDIATE
如果此時還原還是不行。可能是刪完進程馬上有新的進程連進來,導致一直失敗。應用程序一直不停的進行數據庫鏈接
這時,可以在單用戶下還原。
設置方式:選中要還原的數據庫-->屬性-->選項-->限制訪問
該值從MULTI_USER修改為SINGLE_USER,此時該數據庫就會顯示為單用戶模式
這是GUI的模式,語句的辦法比較簡單
USE MASTER
Go
ALTER DATABASE 數據庫名字 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
設置單用戶數據庫必須要超級用戶
或者使用
刪除連在上面的進程,回滾未提交的事務,然后還原。
1.查詢要還原的數據庫ID
Select * from master..sysdatabases where name = '';
2.獲取該數據庫的進程
Select * from sys.sysprocesses a where a.dbid = '';
3.殺掉連接在上面的進程
kill @spid;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。