You could run a RESTORE HEADERONLY on the backup file to read the contents and get the ServerName column.
CREATE DATABASE BLABLA
backup database BLABLA
to disk = 'c:\temp\BLABLA.BAK'
RESTORE HEADERONLY FROM DISK = 'c:\temp\BLABLA.BAK'
With the servername column being the one you want for the backup(s) residing in the backup file....
When restoring a database, is there a way to restore the plan cache so it doesn't have to be re-created during production use?
No. The caches will have to warm up based on use. You can force plans using the Query Store for particular queries if you want, as the Query Store is part of the database, and will be present after Restore.
From your question, it sounds like the restore has been working daily, for some time. As of today it suddenly stopped working.
Yesterday it restored fine with a restored size of around 160GB today it needs 288GB to restore.
One of two things probably happened (or a combination of both)
The data files (mdf.ndf.) grew a bunch either from lots of new data ...
I think you need to revise your question with clarity:
Olas scripts meant for following, not for restoring database.
DBCC - Integrity Check
Maintenance - Index and Statistics
Aside from this, you cannot DROP or RESTORE a database while it's part of Availability Group. You can remove a database from availability group with following commands:
Check the following solution:
Check security permission for user
Go to the location of the backup folder where you have stored the.BAK file
Right click on the backup file and select Properties
Go to Security Tab
Now check the Deny permission for Authenticated users
Click on Edit and remove the Deny
Manually delete the ...