March 6, 2020 at 5:11 pm
Hello,
I am doing some testing and looking at Filegroup articles, specifically:
https://www.sqlshack.com/database-filegroups-and-piecemeal-restores-in-sql-server/
Piecemeal restore. but I am wondering if I can apply the filegroup backup from one database to another, specifically restoring only a particular filegroup of the database, and not have to backup the entire database, and restore it the second database filegroup, if its the exact copy of the database, the purpose would be for archiving (the secondary database is for archiving). wondering how and what steps to do, I tried the following using the backup from the main database SQLShackFGDB and tried to apply the backup filegroup to the secondary database SQLShackFGDB_2, which I used this tsql statement below:
RESTORE DATABASE SQLShackFGDB_2
FILE = 'archiveData',
FILEGROUP = 'SecondarySQLShackFGDB'
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Backup\SecondarySQLShackFGDB.bak'
WITH NORECOVERY
GO
then after that I get the following error message:
Msg 3154, Level 16, State 4, Line 41
The backup set holds a backup of a database other than the existing 'SQLShackFGDB_2' database.
Msg 3013, Level 16, State 1, Line 41
RESTORE DATABASE is terminating abnormally.
I tried to also include "Replace" instead of NORECOVERY and include both REPLACE,NORECOVERY, however still same error message. I also did NORECOVERY because I also wanted to apply the transaction log backup using this tsql statement below:
RESTORE LOG SQLShackFGDB_2
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Backup\SQLShackFGDBTaillog.trn'
WITH RECOVERY
GO
However I haven't got that far yet, any input, advice help or even maybe another route would be great, as I would like to automate this in the future.
thanks in advance
March 6, 2020 at 8:11 pm
Hello Everyone
just an update, I tried to do the following from this Article URL, however so far nothing works 🙁
https://www.systoolsgroup.com/how-to/fix-error-3154-in-sql-server/
March 7, 2020 at 3:15 pm
... but I am wondering if I can apply the filegroup backup from one database to another, specifically restoring only a particular filegroup of the database...
To the best of my knowledge and some experimentation in the past, the answer here is a solid "No". I'm not even aware of a method of restoring a read_only file group to a different database. Piecemeal restores to the original database? Sure... but not to a different database. I've not done a deep dive on it but I believe the problem is mis-matched LSNs and I'm not aware of a viable work around for such a thing.
As with all else, though, "It Depends" and I could be wrong there. We'll see what others have to say on the subject and, if there is a way others come up with, we'll both learn something new and useful.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 9, 2020 at 4:27 pm
Hello Jeff and DinoRS, thank you for your input, sorry the secondary or the other filegroup is not read only, though knowing this now thanks for the info, just wondering if its possible still if the filegroup is not read_only?
March 10, 2020 at 12:09 am
No... you still have the LSN problem.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 12, 2020 at 9:13 pm
Hey Everyone, thank you for all your input, so here is my question and situation of thinking of a solution.
I want to copy data from a certain filegroup, dynamically by month (or day) and copy it to archiving, then delete the data.
I assume the best thing is create a new table/filegroup, then use SSIS, do a SQL statement task, to get the data, and ETL it to the data into the new table/filegroup warehouse, then after that delete all the data from the file group and delete the file group... would that be best?
March 12, 2020 at 10:24 pm
You might want to look into partitioning. If I had it to do over again (I had a similar requirement), I'd have used a Partitioned VIEW instead of a Partitioned TABLE.
If the Archive database is on the same server, there's no way I'd bother with SSIS. It can all be done in a stored procedure and triggered by a monthly job.
One of the biggest advantages of creating 1 file in 1 file group for each month is that you can set the file groups for the older months to READ_ONLY so that you no longer need to back them up or maintain their indexes, etc. Another advantage is that you don't have to do deletes... just drops.
Both Partitioned Views and Partitioned Tables have advantages and disadvantages. Partitioned Views have some extreme advantages if you need to make partial copies for lower environments (which is why I like them) but you should really read up about both. Most people make the mistake of doing trivial research and little planning for such things and this is something that you really need to plan well.
An example might be that you want the whole shebang, including the current (and empty next month, which is a MUST) to live on the Archive database so you don't need to even do a copy.
Like I said, study both methods before you even think of planning anything on this.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply