How to backup a MsSQL database to a Share

 Use a MsSQL query to backup a database to a network share:

EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE
EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE

exec master.dbo.xp_cmdshell 'net use Z: \\sharename password /user:user'
BACKUP DATABASE Staging TO DISK='Z:\database.bak'
EXEC master.dbo.xp_cmdshell 'net use /delete Z:'

EXEC master.dbo.sp_configure 'xp_cmdshell', 0
RECONFIGURE
EXEC master.dbo.sp_configure 'show advanced options', 0
RECONFIGURE

Leave a Reply

Your email address will not be published. Required fields are marked *