Back up the database and generate RAR

Source: Internet
Author: User
Code
-- ----------------------------------
-- -Back up the database
-- -Parameter: Backup folder address, database name exec dbbackup 'd: \ dbbak \ ', 'ihpmp'
-- -Note:
-- -1. You need to create a database folder and a RAR folder.
-- -2. Start the xp_cmdshell permission and configure the application configurator on the SQL Server peripheral.
-- -------------------------------------
Create   Procedure   [ DBO ] . [ Dbbackup ]  
@ Prefix   Nvarchar ( 100 ), -- Backup folder
@ Dbname   Nvarchar ( 100 ) -- Database Name
As

Declare  
@ Datefile   Nvarchar ( 100 ),
@ Bakfile   Nvarchar ( 100 ),
@ Rarfile   Nvarchar ( 100 ),
@ Delcmd   Nvarchar ( 100 ),
@ Rarcmd   Nvarchar ( 150 ),
@ Bakname   Nvarchar ( 150 )

Set   @ Bakname = @ Dbname + ' Data backup '
Set   @ Datefile = @ Dbname + Cast ( Year ( Getdate ()) As   Varchar ( 4 )) + Cast ( Month ( Getdate ()) As   Varchar ( 2 )) + Cast ( Day ( Getdate ()) As   Varchar ( 2 ))
Set   @ Bakfile = @ Prefix + @ Datefile + ' . Bak '  
Set   @ Rarfile = @ Prefix + ' RAR \ ' + @ Datefile + ' . Rar '  
Backup   Database   @ Dbname   To   Disk   =   @ Bakfile   With Init, nounload, name =   @ Bakname , Noskip, stats =   10 , Noformat
Set   @ Delcmd   =   ' Del ' + @ Prefix +   ' RAR \ *. rar ' -- First clear the RAR backup folder
Set   @ Rarcmd   = ' C: \ progra ~ 1 \ WinRAR \ winrar.exe A-p123 ' + @ Rarfile + '   ' + @ Bakfile   -- Change yourpw to the password you want to set for encrypted Compression

Exec Master .. xp_mongoshell @ Delcmd
Exec Master .. xp_mongoshell @ Rarcmd

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.