Monthly I need to sync a SQL Server database. Basically the source database generates a .bak
file, then I take that file and restore it to the destination database.
That worked for the first few times, now the destination database changed because there were some users added, and some tables created.
I thought to open the .bak
file, query the destination DB, removing the duplicates and then do and INSERT with only the new data.
Is that something reasonable?
How can I read/open a .bak
file?
Also, I have been following this instructions
Basically it's my problem, but it use robocopy, as well jobs and I can't use them now.
It use this code to restore the backup:
PRINT '*** Restore full backup of DB $(DB) ***'
:CONNECT $(TGT)
GO
USE [master]
GO
IF EXISTS (SELECT * FROM sys.databases WHERE name = '$(DB)')
BEGIN
ALTER DATABASE $(DB)
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE $(DB)
END
RESTORE DATABASE $(DB)
FROM disk = '$(RESTORE_PATH)\$(DB).bak'
WITH RECOVERY, NOUNLOAD, STATS = 10, REPLACE,
MOVE '$(DATAFILENAME)' TO '$(RESTORE_DATA_PATH)\$(DATAFILENAME).mdf',
MOVE '$(LOGFILENAME)' TO '$(RESTORE_DATA_PATH)\$(LOGFILENAME).ldf'
GO
From what I remember from SQL Server, it will restore the entire database. Is it possible to restore only one table?
Thanks