Quantcast
Viewing all articles
Browse latest Browse all 4871

How to compress DB backup file with sql query

I backup my database with this query:

USE DBName

GO

DECLARE @FileName VARCHAR(MAX)

SET @FileName = 'C:\Backup\SQLDB\DBName_'+ REPLACE(CONVERT(varchar(10),getdate(),103),'/','') + '_' + REPLACE(CONVERT(varchar(10),getdate(),108),':','') + '.Bak'

BACKUP DATABASE DBName

TO DISK = @FileName

WITH FORMAT,

NAME = 'Full Backup of DBName'

GO

I execute this query with a batch file and batch file runs by schedule task.

batch file parameters:

sqlcmd -d DBName -S .\SQLEXPRESS -I -U DBUserName -P DBUserPwd -i SQL_FileName_with_Extension -o log.txt

It successfully backup my database on daily basic and I got backup file with 'DBName_01082014_131210.bak' name. But it's size is too high (around 7GB). Is there any sql query which executes with above query and which can backup and compress my DB at the same time?


Viewing all articles
Browse latest Browse all 4871

Trending Articles