---- 步骤一 打开高级设置 EXEC sp_configure 'show advanced options', 1; GO RECONFIGURE; GO EXEC sp_configure 'xp_cmdshell',1 GO RECONFIGURE GO ---步骤二 建立 磁盘映射 --确保 网络地址 \192.168.0.1ackup 可访问。 -- Z: 为映射的虚拟磁盘符 --password 为远程访问的密码 --domianusername 为远程计算机的用户名,如果是本机 domian 就写计算机名
EXEC XP_CMDSHELL 'net use Z: \192.168.0.1ackup password /user:domianusername'
-- 步骤三 查看文件名称
select * from sys.database_files
--步骤四 还原 --使用 \192.168.0.1ackup 的 test.bak 文件 还原 --还原后问题件位置放在 D盘的xxxx位置。 restore database Marketing from disk='Z:\test.bak' with move 'Marketing' to 'D:Program FilesMicrosoft SQL ServerMSSQL15.MSSQLSERVERMSSQLDATA est.mdf', move 'Marketing_log' to 'D:Program FilesMicrosoft SQL ServerMSSQL15.MSSQLSERVERMSSQLDATA est_log.ldf' -- 步骤五 备份 (如果需要) backup database Marketing to disk='Z:\test.bak' with init --步骤六 查看备份还原进度 SELECT DB_NAME(er.[database_id]) [DatabaseName], er.[command] AS [CommandType], er.[percent_complete], er.start_time, CONVERT(DECIMAL(5, 2), er.[percent_complete]) AS [Complete_Percent] ,CONVERT(DECIMAL(38, 2), er.[total_elapsed_time] / 60000.00) AS [ElapsedTime_m] ,CONVERT(DECIMAL(38, 2), er.[estimated_completion_time] / 60000.00) AS [EstimatedCompletionTime_m] FROM sys.dm_exec_requests AS er WHERE --DB_NAME(er.[database_id]) in ('xxxx') and er.[command] in ( 'RESTORE DATABASE' ,'BACKUP DATABASE') order by er.start_time desc