Recently, we have received a strange request from our customer. They want us to set up a schedule a backup job that generates a backup of SQL database, compress the backup file in multiple compressed archive files (WinRAR files.) We tried to explain to the customer that the SQL Server native backups are capable of compressing the backup file, and it can split a large and compressed backup into multiple backup files. But they insisted us to use the WinRAR software to compress and split the backup.
The IT team of the company has set up the network drive to save the backup file. To accomplish the task, we had taken the following approach:
For the demonstration, I have installed WinRAR software from here, restored a SQL database named AdventureWorks2017 on my workstation.
To set the environment variable, Open Control Panel Click on System. See the following image:
A dialog box, Systems opens. (Screen 1). On the dialog box, click on Advance System properties. On System Properties dialog box (Screen 2), click on the Advanced tab. In the Advanced tab, click on Environment variables. See the following image:
A dialog box environment variable opens. From User Variable for list box, select PATH and click on Edit. See the following image:
A dialog box named Edit environment variable opens. On the dialog box, click on New and add the location of the Winrar.exe file. Click on OK to close the Environment Variables dialog box. See the following image:
Click OK to close the environment variable dialog box and click OK to close the System Properties dialog box.
We will use a SQL Server stored procedure to generate the backup. The logic of the stored procedure is as follows:
The stored procedure accepts the following input parameters:
#backup and restore #maintenance #database