Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeTimeWorker committed Sep 15, 2021
1 parent b631fb9 commit 0140b62
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,14 @@ static void restore()
var databaseName = headInfo[0].DatabaseName;
var dataName = fileInfo[0].LogicalName;
var logName = fileInfo[1].LogicalName;
var stopConnect = $"ALTER DATABASE {databaseName} SET OFFLINE WITH ROLLBACK IMMEDIATE";
string restorSql = $@"RESTORE DATABASE {databaseName} from disk= N'{item}'
WITH NOUNLOAD,
{(replace ? "REPLACE," : "")}
MOVE '{dataName}' TO '{Path.Combine(recoverDir, string.Concat(databaseName, ".mdf"))}',
MOVE '{logName}' TO '{Path.Combine(recoverDir, string.Concat(databaseName, ".ldf"))}';";
Console.WriteLine($"正在关闭数据{databaseName}的当前连接");
context.SqlQuery<dynamic>(stopConnect);
Console.WriteLine($"正在还原{databaseName}");
context.SqlQuery<dynamic>(restorSql);
Console.WriteLine($"还原{databaseName}成功");
Expand Down

0 comments on commit 0140b62

Please sign in to comment.