DECLARE @prefix VARCHAR(64) = 'Dev_LDS_Dev_LSS'
DECLARE @path VARCHAR(256) = 'E:\DB_Backup\Alex\'
DECLARE @dbname VARCHAR(256)
DECLARE @filename VARCHAR(256)
DECLARE @date VARCHAR(32)
SELECT @date = CONVERT(VARCHAR(20),GETDATE(),112)
DECLARE db_cursor CURSOR FOR
SELECT [name]
FROM sys.databases WHERE [name] like @prefix + '%'
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @dbname
WHILE @@FETCH_STATUS = 0
BEGIN
SET @filename = @path + @dbname + '_' + @date + '.bak'
BACKUP DATABASE @dbname TO DISK = @filename
PRINT @filename
FETCH NEXT FROM db_cursor INTO @dbname
END
CLOSE db_cursor
DEALLOCATE db_cursor