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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Khan Abrar AhmedRank #778 · 3K reputationPosted May 18, 2014, 12:50 AM EDT
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
Anupam SinghRank #643 · 3.7K reputationPosted May 18, 2014, 4:26 AM EDT
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.