Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Backup file name

Author  Topic 

ranvir_2k
Posting Yak Master

180 Posts

Posted - 2014-02-06 : 11:58:45
Hi all,

I want to restore a full database backup taken by a SQL Server maintenance plan. I want to do this via an automated script.

The full backup file name would be of the format:
MyDatabase_backup_201402060153.bak

Unfortunately the transaction logs for the same database are backed up to the same location as the full backup and are of the format:
MyDatabase_backup_201402061600.trn

Let's say the folder they are stored in is called:
\\ThePath



declare @Exe varchar(100)

set @Exe = 'dir \\ThePath\MyDatabase_backup_' + convert(varchar(10),getdate(),112) + '*'


I was using this code to get the full database backup name but it will return the transaction log backups as well due to the way microsoft have named transaction log backups.

Is there anyway I can add the .bak to my code, so that it only returns the .bak files?

i.e. it ignores the time and only looks for the date and the .bak extension.

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-02-06 : 12:17:08
Change '*' to '*.bak'

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

ranvir_2k
Posting Yak Master

180 Posts

Posted - 2014-02-06 : 12:26:04
Many Thanks Tara!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-02-06 : 15:51:16


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -