It backs up with an expiration of 30 days, but a year for anything on the first of the month.
Emails if it fails… (assume that you have sql email profile already setup)
CREATE PROCEDURE spBackupAllDatabases
AS
BEGIN
SET NOCOUNT ON;
declare @db varchar(50)
declare @d varchar(100)
declare @n varchar(100)
declare @rd int
set @rd=case when datepart(day,getdate())=1 then 365 else 30 end
declare db cursor for select name from sys.databases
where name not in ('master','tempdb','model','msdb')
open db
begin try
fetch next from db into @db
while @@FETCH_STATUS=0
begin
set @d='c:\\backup sql server\'+@db+'.bak'
set @n=@db+'-Full Database Backup'
backup database @db to disk=@d
with retaindays=@rd, noformat, noinit, name=@n,
skip, norewind, nounload, stats=10
fetch next from db into @db
end
end try
begin catch
--sending emails
exec msdb.dbo.sp_send_dbmail
@profile_name='myprofile', @recipients='me@domain.com',
@subject='SQL Server Backup failed on SQL Server',
@body='The SQL Server Backup Operation failed on the SQL Server.',
@body_format='HTML'
end catch
close db
deallocate db
end
GO
SnowTweet
Xe Dap Oi !