Hi @S_NO ,
To restore a full backup followed by multiple log backups, you can use the following sequence of commands:
RESTORE DATABASE <dbname> FROM DISK='<path to full backup file>' WITH NORECOVERY;
RESTORE LOG <dbname> FROM DISK='<path to first log backup file>' WITH NORECOVERY, STATS=10;
RESTORE LOG <dbname> FROM DISK='<path to second log backup file>' WITH NORECOVERY, STATS=10;
...
RESTORE LOG <dbname> FROM DISK='<path to last log backup file>' WITH RECOVERY, STATS=10;
Make sure to specify WITH NORECOVERY for all log backups except for the last one, which should be followed by WITH RECOVERY to bring the database online.
To copy log backup files from one server to another server while avoiding duplicates and maintaining the correct sequence, you can use robocopy or PowerShell script to automate the process. Here is an example of PowerShell:
$sourcePath = "<path to source folder>"
$destinationPath = "<path to destination folder>"
# Get a list of all log backup files in the source folder
$logFiles = Get-ChildItem $sourcePath -Filter "*.trn" | Sort-Object LastWriteTime
# Check if the destination folder exists; create it if it doesn't
if (!(Test-Path $destinationPath)) {
New-Item -ItemType Directory -Path $destinationPath
}
# Copy each log backup file to the destination folder
foreach ($logFile in $logFiles) {
$destinationFile = Join-Path $destinationPath $logFile.Name
if (!(Test-Path $destinationFile)) {
Copy-Item $logFile.FullName $destinationFile
}
}
Best regards,
Seeya
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".