how to backup and restore database of SQL Server

Back up

1,右键选中需要备份的数据库,Tasks-->Backup

 

2.General中,Destination,先remove掉之前的,然后再Add

需要注意的是,add的文件,必须要以.bak为后缀名,否则后面restore的话,不会显示出备份的文件

 

 

Restore

1.在数据库服务器的Databases上右键,选择Restore Database

1.1  General选项卡

    1.1.1选择Device进行浏览,找到之前备份的文件。在查看文件的时候,默认是查看.bak文件。   

            不过也可以选择all files,那样可以看到所有的文件

    1.1.2  General里面,Destination中的Database需要起一个不同的名字,这个名字是显示在ManagementStudio中的

选择路径之后,点击刷新的图标,然后下方会自动筛选

 

 可以同时添加多个备份数据库,但是每一个数据库的restore plan是需要切换选项卡来进行独立设置的

1.2  Files选项卡

      在General中,每切换一个数据库,Files选项卡中都需要独立配置一下

      Logical File中的Rows Data和Log,都需要进行重命名,确保不重名。Restored as 这个列的里面的数据需要重命名

      这里需要按照需要进行重命名

1.3  Options选项卡

       取消勾选Tail-log backup

 

Restore failed

 

 

Restore failed

TITLE: Microsoft SQL Server Management Studio
------------------------------

Restore of database 'd_lisa_Program_dev01_v5000' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)

------------------------------
ADDITIONAL INFORMATION:

System.Data.SqlClient.SqlError: The tail of the log for the database "d_lisa_Program_dev01_v5000" has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log. (Microsoft.SqlServer.SmoExtended)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=12.0.6024.0+((SQL14_PCU_Main).180907-0056)&LinkId=20476

------------------------------
BUTTONS:

OK
------------------------------

https://stackoverflow.com/questions/12370944/the-tail-of-the-log-for-the-database-dbname-has-not-been-backed-up

The error message you are getting tells you exactly what you need to do if you don't care about the existing database or log.

RESTORE DATABASE DAtabaseName FROM DISK = 'C:\DBName-Full Database Backup' 
WITH REPLACE

In SQL Server Management Studio (Tasks > Restore), you can add the WITH REPLACE option by opening the page "Options" on the left side and ticking "Overwrite the existing database".

 

 

 

官方文档

https://msdn.microsoft.com/en-us/library/ms187510(v=sql.110).aspx  仅针对于SQL Server 2012

https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/create-a-full-database-backup-sql-server   针对于SQLServer 2016

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(487)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示