简体   繁体   English

使用bak文件从另一台计算机还原数据库

[英]Restore database using a bak file from another computer

I have a SQL Server database on my PC. 我的PC上有一个SQL Server数据库。 I backed up my database so now I have a .bak file. 我备份了数据库,所以现在有了一个.bak文件。

I recently brought a new PC and want to move the database from my old PC to this PC. 我最近带来了一台新PC,并希望将数据库从旧PC移至该PC。

I go to restore database & under source click on device. 我去恢复数据库,并在源下单击设备。 I then have the backup media type as file & then click Add. 然后,将备份媒体类型作为文件,然后单击添加。 I browse to where my .bak file is. 我浏览到.bak文件所在的位置。 However when I browse to this directory no files show up which I don't understand why? 但是,当我浏览到该目录时,没有文件显示,我不明白为什么?

Can I not just copy over the backup file from my old PC to my new one? 我不仅可以将备份文件从旧PC复制到新PC吗? What am I missing? 我想念什么?

I do it manually. 我手动完成。 First, find out where your new server keeps it's database (mdf) and log (ldf) files 首先,找出新服务器将其保存在数据库(mdf)和日志(ldf)文件中的位置

SELECT name, physical_name FROM sys.master_files

Then, find out what the logical names of those files are in your backup 然后,找出备份中这些文件的逻辑名称

restore FILELISTONLY FROM DISK='c:\dir\file.bak'

Finally, use combine that info to do the restore: 最后,使用合并该信息来进行还原:

RESTORE DATABASE DataBaseToCreate
    FROM DISK = 'c:\dir\file.bak' 
    WITH REPLACE, 
    MOVE 'DBLogicalName' TO  'C:\DB_DIR\DataBaseToCreate.mdf'
    MOVE 'LogLogicalName' TO  'C:\LOG_DIR\DatabaseToCreate.ldf'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM