The plan is to have 1 backup set that will contain full and transactional log backup. (Server1)
There is already a scheduled job that will append any transactional log to the file after 30 minutes. (Server1)
There is a shared network drive between Server1 and Server2. But the problem is automating it via T-SQL. Here is the script:
RESTORE LOG [db_test_rep] FROM DISK = N'Z:\db_rep.bak' WITH FILE = 19, NORECOVERY, NOUNLOAD, STATS = 5
The issue with this is that everytime the scheduled job executes, it will update the backup file numbering + 1. So in this case on the next transaction log backup, when I script into action the restoration using SSMS, it will generate FILE = 20
Can you guys give me a simple workaround for this?
Best Answer
Maybe something like this:
Get the latest FILE number by using RESTORE FILELISTONLY:
Then do your restore using dynamic SQL: