I had a migration from SQL Server 2014 to SQL Server 2022.
I first created FULL backups from the SQL Server 2014 instance, and then ran RESTORE DATABASE
script shown below to do a test migration. Everything worked as planned.
A week later, I dropped all of the databases on the new server, backed up SQL Server 2014 again to the same file names, and then again ran the below script. SQL Server 2022 however did not restore the latest version of the file, and instead restored only the week old data. Only right-clicking in the UI and doing a "restore" from there restored the current version of the data.
Can someone please help me understand why that is to prevent it in the future?
BACKUP DATABASE db1 TO DISK = db1.BAK;
RESTORE DATABASE [db1]
FROM DISK = N'\\sql2014\migration\db1.BAK' WITH FILE = 1,
MOVE N'db1_data' TO N'D:\Data\db1_data.mdf',
MOVE N'db1_log' TO N'D:\Log\db1_log.ldf',
NOUNLOAD,
REPLACE,
STATS = 5;
GO
db1.BAK
contain more than one backup? Won'tFILE = 1
be the oldest one? What doesRESTORE HEADERONLY
/RESTORE FILELISTONLY
tell you about this file? Also, always useWITH INIT, FORMAT
when creating backups because I've never understood why anyone - in the last two decades anyway - would want to combine multiple backups into a single file.RECOVERY
orNORECOVERY
depending on whether you just want to restore the backup or you have further actions (like restoring further logs).