发布:2024/5/30 0:02:20作者:管理员 来源:本站 浏览次数:492
Linux sqlServer数据库还原办法
一、mdf文件方式
一、拷贝文件到对应目录
/var/opt/mssql/data/
二、给文件授权(xxx是指数据库文件名)
chmod 777 xxx*
三、执行命令
USE [master]
GO
CREATE DATABASE [xxx] ON
( FILENAME = N'/var/opt/mssql/data/xxx.mdf' ),
( FILENAME = N'/var/opt/mssql/data/xxx_log.ldf')
FOR ATTACH
GO
二、备份文件方式
一、登录数据库
sqlcmd -S 127.0.0.1 -U sa
image.png
二、查询数据库、数据库日志实例名
RESTORE FILELISTONLY FROM DISK = '/opt/new-products/ogis/ogis_20190521.bak'
** 三、还原数据库(注意:还原目标数据库不能提前创建)**
RESTORE DATABASE ogis(目标数据库) FROM DISK = '/opt/new-products/ogis/ogis_20190521.bak'
WITH
MOVE 'ogis(实例名)' TO '/var/opt/mssql/data/ogis.mdf',
MOVE 'ogis_log(实例名)' TO '/var/opt/mssql/data/ogis.ldf'
GO
** 三、已存在数据库bak方式还原**
RESTORE DATABASE [ogis(目标数据库)]
FROM DISK = N'/var/opt/mssql/data/ogis_1117.bak'
WITH FILE = 1, REPLACE
-------------------还原到目标位置-----------------------
restore database zhck from disk = N'/var/opt/mssql/data/zhck_base.bak'
with RECOVERY,REPLACE,
move 'zhck_base' to '/var/opt/mssql/data/zhck_base.mdf',move 'zhck_base_log' to '/var/opt/mssql/data/zhck_base_log.ldf';
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4