Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Wildcard restore of database

$
0
0

I have a script I am currently using each day to restore a database provided by a vendor. The file name of the backup from the vendor is similar to 'My_Vendors_Data_FULL_20181024_230000.bak' which includes the date and time of the backup.

SQL
USE[master]GOALTERDATABASE[My_Vendors_Data]SETSINGLE_USERWITHROLLBACKIMMEDIATEGODECLARE@yesterdaydatenvarchar(8)=(SELECTFORMAT(GETDATE()-1,'yyyyMMdd')AS[YYYYMMDD])-- Yesterday's date for backupDECLARE@backupnvarchar(200)='\\myserver\My_Vendors_Data_FULL_'+@yesterdaydate+'_230000.bak'RESTOREDATABASE[My_Vendors_Data]FROMDISK=@backupWITHRECOVERY,REPLACE,STATS=10;GO

Typically, the time format in the file name is ' 230000' for 11:00 PM. However, on occasion the time is ' 230001' or '230002'. This will cause a failure because there is no filename that...


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>