2

I'm attempting to restore a database that has multiple .trn files, Is there a way to list every tlog in a directory, and then use a write-host to each file with the proper tsql so it can restore i.e.

$Path = "S:\S_Logs"

$TSQL = "RESTORE Log FPRD FROM DISK = N'$Path\$Logs' WITH NORECOVERY, NOUNLOAD, STATS = 20"

$Logs =  gci $Path -Filter "*.ldf" | Sort-object -property LastWriteT | Write-Output

I'm sure there is a better way, and I'm possibly going about it the worst way, but any advice will help.

1 Answer 1

1

This problem is solved for you already. Get the dbatools module from the PowerShell Gallery and check out Restore-DbaDatabase.

Restore-DbaDatabase -path s:\s_logs -sqlserver YOURSERVER -RestoreTime RESTORE_POINT -DatabaseName YOURDATABASE
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.