Skip to main content
Solved

Automate default backup at every deployment, anyone already made this and cares to share?


Freddy
Forum|alt.badge.img+16
  • Thinkwise Local Partner Brasil

Just a question, out of perhaps laziness :)

Personally I always tend to forget to make a backup before a deployment..  anyone by chance already made a solution for this in the SF and cares to share it?  ..   

Best answer by John Sangers

Hi Freddy,

We added a template with a piece of code to the ug_before_upgrade_always program object:

SET @name = (SELECT DB_NAME()) 

BACKUP DATABASE @name TO DISK = @filename

where the the @filename is composed of the settings we use on our server, the path can be determined using:
   EXEC master.dbo.xp_instance_regread 
            N'HKEY_LOCAL_MACHINE', 
            N'Software\Microsoft\MSSQLServer\MSSQLServer',N'BackupDirectory', 
            @path OUTPUT,  
            'no_output'

View original
This topic has been closed for comments

John Sangers
Apprentice
Forum|alt.badge.img+1

Hi Freddy,

We added a template with a piece of code to the ug_before_upgrade_always program object:

SET @name = (SELECT DB_NAME()) 

BACKUP DATABASE @name TO DISK = @filename

where the the @filename is composed of the settings we use on our server, the path can be determined using:
   EXEC master.dbo.xp_instance_regread 
            N'HKEY_LOCAL_MACHINE', 
            N'Software\Microsoft\MSSQLServer\MSSQLServer',N'BackupDirectory', 
            @path OUTPUT,  
            'no_output'


Freddy
Forum|alt.badge.img+16
  • Thinkwise Local Partner Brasil
  • August 4, 2023

@John Sangers it's that easy :) 

Thanks!

As we use containers, I did it as followed:

declare @database       varchar(30)		= (select DB_NAME())
declare @path           varchar(150)    = '/var/opt/mssql/backup/'
declare @target         varchar(260)    = @path + @database + '.bak'

BACKUP DATABASE @database
    TO DISK = @target
	WITH FORMAT;

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings