MSSQL Server Database Backup statements

Source: Internet
Author: User
Tags getdate mssql mssql server rar

MSSQL Server Database Tutorial Backup statements

DECLARE @exec_str varchar (60)
DECLARE @exec_str_rar varchar (60)
DECLARE @exec_str_diff varchar (60)
DECLARE @exec_str_rar_diff varchar (60)
DECLARE @DEL_DATE_4 char (8)
Select @DEL_DATE_4 = Convert (char (8), DATEADD (Dd,-4,getdate ()), 112)
--Processing database SZC 4 days with additional preparation
Select @exec_str = ' del F:db_backxtoadb_full_ ' + @DEL_DATE_4 + '. Bak '
Select @exec_str_rar = ' del D:db_back_rarxtoadb_full_ ' + @DEL_DATE_4 + '. rar '
Select @exec_str_diff = ' del f:db_backdifferentxtoadb_diff_ ' + @DEL_DATE_4 + ' *.bak '
Select @exec_str_rar_diff = ' del d:db_back_rardifferentxtoadb_diff_ ' + @DEL_DATE_4 + ' *.rar '
EXEC master.. xp_cmdshell @exec_str, No_output
EXEC master.. xp_cmdshell @exec_str_rar, No_output
EXEC master.. xp_cmdshell @exec_str_diff, No_output
EXEC master.. xp_cmdshell @exec_str_rar_diff, No_output
--Processing database szcstatistics 4 days
Select @exec_str = ' del f:db_backxtoadbstatistics ' + @DEL_DATE_4 + '. Bak '
Select @exec_str_rar = ' del d:db_back_rarxtoadbstatistics ' + @DEL_DATE_4 + '. rar '
EXEC master.. xp_cmdshell @exec_str, No_output
EXEC master.. xp_cmdshell @exec_str_rar, No_output
--Processing database Szclog 4 days
Select @exec_str = ' del f:db_backxtoadblog ' + @DEL_DATE_4 + '. Bak '
Select @exec_str_rar = ' del d:db_back_rarxtoadblog ' + @DEL_DATE_4 + '. rar '
EXEC master.. xp_cmdshell @exec_str, No_output
EXEC master.. xp_cmdshell @exec_str_rar, No_output
Go

--2. Step Two: Database backup processing

Select ' Backup start time: ' = GETDATE ()
Declare @RCL_DATE char (8)
Select @RCL_DATE = Convert (char (8), GETDATE (), 112)
D Eclare @PATH varchar
--Backup of database SZC--With differential backup
Select @PATH = ' f:db_back ' + ' Xtoadb_full_ ' + @RCL_DATE + '. Bak '
Backup LOG xtoadb with TRUNCATE_ONLY
Snapup db xtoadb to DISK = @PATH with INIT
-database Szcstatistics backups
Select @PATH = ' f:db_back ' + ' xtoadbstatistics ' + @RCL_DATE + '. Bak '
--backup LOG xtoadbstatistics with TRUNCATE_ONLY
--backup db xtoadbstatistics to DISK = @PATH
--Backup of database Szclog
Select @PATH = ' f:db_back ' + ' Xtoadblog ' + @RCL_DATE + '. Bak '
--backup LOG xtoadblog with TRUNCATE_ONLY
--backup the DATABASE xtoadblog to DISK = @PATH
go? "

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.