存储过程备份数据库

ALTER PROCEDURE [dbo].[pro_backupDB]
        
AS

BEGIN
    SET NOCOUNT ON;

    declare @fileName nvarchar(255),@path nvarchar(255),@DataBase nvarchar(50);
    set @path='D:\webfile\dbBackFile\RMmsDB\';
    set @DataBase='Ribecs';
    set @fileName = @path+CONVERT(varchar(10), GETDATE(), 23)+'_Ribecs.BAK';

    backup database @DataBase to Disk = @fileName with init;

    /*Delete Old------------------------------*/
    declare @olddate DATETIME

    /*删除14天以前的备份数据*/

    set @olddate = getdate()-14;

    execute master.dbo.xp_delete_file 0,@path,N'BAK',@olddate;

END

 

posted @ 2014-04-04 11:22  梦醒心晴  Views(312)  Comments(0Edit  收藏  举报