Master. DBO. xp_mongoshell

Source: Internet
Author: User
Tags rowcount

Create procedure [DBO]. [usp_data_backup] (@ database as varchar (100)
Begin
Declare @ bk_max_count as int,
@ Sqlstring as nvarchar (500 ),
@ Fname as varchar (100 ),
@ Path_prefix as varchar (100 ),
@ Variable_fname as varchar (100 ),
@ Del_variable_fname1 as varchar (100 ),
@ Del_variable_fname2 as varchar (100 ),
-- @ Database as varchar (100 ),
@ Devicename as varchar (100 ),
@ Log_devicename as varchar (100 ),
@ Shellstring as varchar (100)

Set @ bk_max_count = 12
Set @ devicename = 'dbk _ '+ @ Database
Set @ log_devicename = 'lbk _ '+ @ Database
Set @ path_prefix = 'd:/data_managerdb_backup /'
Set @ variable_fname = convert (char (8), getdate (), 112)
+ Convert (varchar (2), datepart (hour, getdate ()))
+ Convert (varchar (2), datepart (minute, getdate ()))

Set @ del_variable_fname1 = convert (char (8), getdate ()-7,112)
Set @ del_variable_fname2 = convert (char (8), getdate ()-7,112)


----------------------------------------------------------

-- Create D:/data_managerdb_backup/Trans
Set @ shellstring = 'mkdir' + @ path_prefix + 'Trans'
Exec master. DBO. xp_mongoshell @ shellstring

-- Create D:/data_managerdb_backup/keeping
Set @ shellstring = 'mkdir' + @ path_prefix + 'keeping'
Exec master. DBO. xp_mongoshell @ shellstring

-- Move the backup file starting with DBK _ in the d:/data_managerdb_backup/Trans folder to D:/data_managerdb_backup/keeping
Set @ shellstring = 'move/y' + @ path_prefix + 'Trans/'+ @ devicename +' _ *. * '+ @ path_prefix + 'keeping'
Exec master. DBO. xp_mongoshell @ shellstring

-- Move the backup file starting with LBK _ in the d:/data_managerdb_backup/Trans folder to D:/data_managerdb_backup/keeping
Set @ shellstring = 'move/y' + @ path_prefix + 'Trans/'+ @ log_devicename +' _ *. * '+ @ path_prefix + 'keeping'
Exec master. DBO. xp_mongoshell @ shellstring
Bytes -----------------------------------------------------------------------------------------------

----------------------------------------------------------------------

-- Delete the backup files starting with DBK _ in the d:/data_managerdb_backup/keeping folder one week ago.
Set @ shellstring = 'del '+ @ path_prefix + 'Keeping/' + @ devicename + '_' + @ del_variable_fname1 + '*. Bak'
Exec master. DBO. xp_mongoshell @ shellstring

-- Delete the backup file starting with LBK _ in the d:/data_managerdb_backup/keeping folder
Set @ shellstring = 'del '+ @ path_prefix + 'Keeping/' + @ log_devicename + '_' + @ del_variable_fname2 + '*. Bak'
Exec master. DBO. xp_mongoshell @ shellstring
Bytes -----------------------------------------------------------------------------------------------

Bytes -----------------------------------------------------------------------------------
Set @ sqlstring = n' select * From sysdevices where name = ''' + @ log_devicename + ''''
Exec sp_executesql @ sqlstring

If (@ rowcount> 0)
Begin
-- Delete the backup file of the disk if it exists.
Exec sp_dropdevice @ logicalname = @ log_devicename
End

--
Set @ fname = @ path_prefix + 'Trans/'+ @ log_devicename +' _ '+ @ variable_fname +'. Bak'
-- Add new disk backup files

Exec sp_addumpdevice 'disk', @ log_devicename, @ fname

Set @ sqlstring = n'backup log' + @ database + 'to' + @ log_devicename + 'with noinit'

-- Back up log files
Exec sp_executesql @ sqlstring
Bytes ------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------
Set @ sqlstring = n' select * From sysdevices where name = ''' + @ devicename + ''''
Exec sp_executesql @ sqlstring

If (@ rowcount> 0)
Begin
--
Exec sp_dropdevice @ logicalname = @ devicename
End

Set @ fname = @ path_prefix + 'Trans/'+ @ devicename +' _ '+ @ variable_fname +'. Bak'
Exec sp_addumpdevice 'disk', @ devicename, @ fname

Set @ sqlstring = n' backup database' + @ database + 'to' + @ devicename + 'with noinit'

-- Back up data files
Exec sp_executesql @ sqlstring
Bytes ------------------------------------------------------------------------------------------------

End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.