Do  FULL Backups for New DBs(run daily)

,

This script will do a full backup of any new database(s) on the server that does not have a backup already. This script runs Monday thru Saturday at our site.

SET QUOTED_IDENTIFIER off
set nocount on
declare @dbname varchar(36),@cmd varchar(255)
declare dbname_cursor cursor
    for
select db.name from master..sysdatabases   db
where db.name != 'tempdb'
and db.name not in (select bs.database_name from msdb..backupset bs where type = "d")
order by db.name

open  dbname_cursor
fetch dbname_cursor into @dbname

while @@fetch_status = 0
begin
if DATABASEPROPERTYEX(@dbname,'Recovery') = 'SIMPLE' and DATABASEPROPERTYEX(@dbname,'Status') = 'ONLINE'
  begin
        select @cmd ='backup database '+@dbname+' to DISK="E:\Program Files\Microsoft SQL Server\MSSQL\backup\'+@dbname+'.bak" with init'
           print @cmd
          execute (@cmd)
  end
fetch dbname_cursor into @dbname
end

close dbname_cursor
deallocate dbname_cursor

Rate

Share

Share

Rate