how to write Stored procedure for back up the files in database using sheduled task in sql server 2008 r2
Thanks&Regards
Selastin C
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Anupam SinghPosted May 18, 2014, 8:26 AM
There are different types of backup in Sql server,
like : full backup, differential backup, transaction log backup.
you can take a full backup using a simple query
BACKUP DATABASE DB_NAME
TO DISK = 'C:\DB_NAME.BAK' // where do you want save backup
GO
Although I would suggest you to read this
you can use Job in sql to schedule this.
Khan Abrar AhmedPosted May 18, 2014, 4:50 AM
Create procedure getDbBackup
as
begin
DECLARE
@FileName varchar (128),
@FilePath varchar (128),
@FilePathName varchar (256),
@DatabaseName varchar (128),
@DatabaseBackupName varchar (256);
set @DatabaseName = 'DB Name'
set @FileName = '_backup_' + REPLACE(convert(varchar,GETDATE(),106),' ','')+'_'+REPLACE(convert(varchar,GETDATE(),108),':','')+'.bak'
If (@@SERVERNAME = 'server name')
begin
set @FilePath = 'Backup location'
End
set @FilePathName = @FilePath+@DatabaseName+@FileName
set @DatabaseBackupName = @DatabaseName+'-Full Database Backup'
BACKUP DATABASE @DatabaseName
TO DISK = @FilePathName
WITH NOFORMAT, INIT,
NAME = @DatabaseBackupName, SKIP, NOREWIND, NOUNLOAD, STATS = 10
end
go