惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News | PayPal Newsroom
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
H
Hacker News: Front Page
Apple Machine Learning Research
Apple Machine Learning Research
TaoSecurity Blog
TaoSecurity Blog
Help Net Security
Help Net Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
人人都是产品经理
人人都是产品经理
博客园 - 三生石上(FineUI控件)
Security Latest
Security Latest
Cloudbric
Cloudbric
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Know Your Adversary
Know Your Adversary
A
Arctic Wolf
L
LangChain Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
小众软件
小众软件
NISL@THU
NISL@THU
云风的 BLOG
云风的 BLOG
P
Privacy & Cybersecurity Law Blog
S
Security @ Cisco Blogs
博客园 - 【当耐特】
I
InfoQ
Vercel News
Vercel News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Proofpoint News Feed
O
OpenAI News
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
量子位
宝玉的分享
宝玉的分享

博客园 - qy1141

Mysql插入Emoji表情出错 spring+mybatis事务不起作用的原因 安卓开发随记 springmvc + spring + ibatis + mysql Eclipse中配置svn J2EE环境配置与工具使用 SqlServer数据库空间使用情况常用命令 关于数据库优化杂技 windows2008吃尽内存的解决办法 asp.net中http提交数据所遇到的那些坑 在C#中使用消息队列RabbitMQ 重新开博 WCF Security系列(2)--服务器端的安全 WCF Security系列(1)--Security概述 如果为网站生成自签名SSL证书 关于证书 转:最真实的2006年应届毕业生真实薪水 转:如何修复Team Foundation Server Workgroup Edition 不小心删除了所有Team Foundation Licensed Users组内用户问题 转 :TFS(Team Foundation Server)使用经验
数据库备份与还原
qy1141 · 2015-09-14 · via 博客园 - qy1141

数据库备份与还原

2015-09-14 12:14  qy1141  阅读(350)  评论()    收藏  举报

备份数据库有很多种方式,我们选择的方案是完整备份+日志备份,等将来数据库大了以后,将变为完整备份+差异备份+日志备份,如图:

每天晚上进行数据库的完整备份,每30分钟进行日志备份,每次日志备份后系统会自动截断日志文件,这也能有效保证日志文件不会无限的增大。

--完整备份数据库
declare @toPath nvarchar(100)
set @toPath = 'D:\bak\Test_' + REPLACE(convert(nvarchar,GETDATE(),20),':','.') + '.bak'
backup database Test to disk = @toPath  with COMPRESSION,password = '123'

--备份事务日志
declare @toLogPath nvarchar(100)
set @toLogPath = 'D:\bak\Test_log_' + REPLACE(convert(nvarchar,GETDATE(),20),':','.') + '.bak'
BACKUP LOG Test To disk= @toLogPath

--备份尾事务日志(在数据库出现故障时,备份最后的日志)
BACKUP LOG Test To disk= @toLogPath with norecovery
--还原数据库
RESTORE DATABASE Test
FROM DISK = 'D:\bak\Test_2015-09-13 07.15.53.bak' 
with norecovery,password = '123',
MOVE N'OA' TO N'D:\db\Test.mdf',  
MOVE N'OA_log' TO N'D:\db\Test.ldf'

--还原事务日志(中间日志)
RESTORE log Test
FROM DISK = 'D:\bak\Test_log2015-09-13 07.16.47.bak' with norecovery

--还原事务日志(最后日志)
RESTORE log Test  
FROM DISK = 'D:\bak\Test_log2015-09-13 07.17.00.bak' WITH recovery

--用stopat恢复尾日志备份
RESTORE log [Test]  
FROM DISK = 'D:\bak\Test_2015-07-19 19.07.40.bak' WITH FILE = 3,stopat = '',recovery

--根据备份文件获取数据库逻辑文件名
RESTORE FILELISTONLY FROM DISK = 'D:\bak\Test_2015-09-13 07.15.53.bak' with password = '123'