I need to make backup copies of my database and store them on another server
I created this stored procedure for that task:
USE [master]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_BackUpRecursosHumanos]
@backupLocation NVARCHAR(200),
@databaseName SYSNAME = NULL
AS
DECLARE @BackupName VARCHAR(100)
DECLARE @BackupFile VARCHAR(100)
DECLARE @DBNAME VARCHAR(300)
DECLARE @sqlCommand NVARCHAR(1000)
DECLARE @dateTime NVARCHAR(20)
--DECLARE @Loop INT
--DECLARE @backupLocation NVARCHAR(200)
SET @DBNAME = @databaseName
SET @backupLocation = @backupLocation
SET @dateTime = REPLACE(CONVERT(VARCHAR, GETDATE(),101),'/','') + '_' + REPLACE(CONVERT(VARCHAR, GETDATE(),108),':','')
SET @BackupFile = @backupLocation+REPLACE(REPLACE(@DBNAME, '[',''),']','')+ '_FULL_'+ @dateTime+ '.BAK'
SET @BackupName = REPLACE(REPLACE(@DBNAME,'[',''),']','') +' full backup for '+ @dateTime
BEGIN
SET @sqlCommand = 'BACKUP DATABASE ' +@DBNAME+ ' TO DISK = '''+@BackupFile+ ''' WITH INIT, NAME= ''' +@BackupName+''', NOSKIP, NOFORMAT'
END
EXEC(@sqlCommand)
Where to create a script:
// Sqlbackup.bat
/****************************************************************/
backup
/***************************************************************/
sqlcmd -S DESKTOP -Q "EXEC sp_BackUpRecursosHumanos @backupLocation='C:\Users\dell\Documents\BackUp\', @databaseName='RecursosHumanos'"
Here is saving the copy internally, My problem is how I keep it on another server
sp_prefix for your stored procedures. Microsoft has reserved that prefix for its own use (see Naming Stored Procedures), and you do run the risk of a name clash sometime in the future. It's also bad for your stored procedure performance. It's best to just simply avoidsp_and use something else as a prefix - or no prefix at all!