SQL Server - Why wont restore complete - sql

I am trying to copy a live database from one instance to a development instance for debugging purposes
The live database is ~200M in size running on on SQL Server 2008 R2 (10.50.4042)
I have tried numerous ways of backing up and restoring, but every time the Restore gets 100% and just sits there
I have tried SQLServer 2016 Developer and SQLServer 2008 R2 Express as development instance , same result
The database is very simple, but something is blocking the restore
BACKUP DATABASE [database] TO DISK = N'D:\file.BAK'
WITH NOFORMAT, NOINIT, NAME = N'Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 5*
The backup literally takes seconds takes seconds, even with compression off it is only 200M in size
The restore takes a few seconds to restore but then just sits at 100%
I have read many articles , none work so tried RECOVERY NORECOVERY
Tried to kill and restore, tried to mount, nothing seems to work.
What other options are there?
RESTORE DATABASE [database] FROM DISK = N'D:\File.BAK' WITH FILE = 1, MOVE N'Instance_Data' TO N'D:..\database.mdf', MOVE N'Instance_log' TO N'D:..\database_1.ldf', NOUNLOAD, RECOVERY, STATS = 5
Live database for Rows Data = 173 MB, the LOG 161,574 MB

Related

How to backup Microsoft SQL Server database to create multiple 100MB .bak files

One .bak file:
BACKUP DATABASE dbName TO DISK = C:\dbname.bak 1200 MB
How to backup Microsoft SQL Server database into multiple .bak files, splinting it to multiple files like DBName01.bak,DBName02.bak,....'DBName0N.bak there N is parameter for number of files.
Where N would be dynamic parameter.
Yes you can take your backups to multiple files, its actually more convenient to have smaller files rather than having one large file.
The syntax for taking backups to multiple files would be:
BACKUP DATABASE [dbName] TO
DISK = N'D:\backups\MultipleFiles\MyDB_Backup_File1.bak',
DISK = N'D:\backups\MultipleFiles\MyDB_Backup_File2.bak',
DISK = N'D:\backups\MultipleFiles\MyDB_Backup_File3.bak'
WITH NOFORMAT, NOINIT, NAME = N'dbName-Full Database Backup'
, SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
The data is distributed equally among all the files, so if you want smaller files use more files to take backups.

Differential backup size is too large

I have a database on SQL Server 2008 R2 SP2, I have this backup plan on that db:
every Friday morning I get a full backup of my db and at noon I get differential backup and the other days of the week I get differential backup twice per day (morning and noon).
The full backup size is about 50 GB. My problem is: the first differential backup size is about 42 GB.
I have no jobs in the time between the full and differential backup and there is no any rebuild index, reorganize index or update stats and the transaction on this db is not more.
In order to test, I get a full backup from db and after this done, I get differential backup from that immediately but the differential backup size is about 42 GB.
Even if I check the DCM page content and after getting full backup this page is reset.
I don't know what is the problem.
Here are my backup commands:
Full backup:
BACKUP DATABASE [test]
TO DISK = N''filePath\test.bak''
WITH NOFORMAT, NOINIT, NAME = 'test', SKIP, REWIND,
NOUNLOAD,COMPRESSION, STATS = 10
DIFF Backup
BACKUP DATABASE [test]
TO DISK = N''filePath\test.bak''
WITH DIFFERENTIAL, NOFORMAT, NAME = 'testdiff', NOINIT, SKIP, REWIND,
NOUNLOAD, STATS = 10
You are specifying NOINIT clause.
Indicates that the backup set is appended to the specified media set, preserving existing backup sets. If a media password is defined for the media set, the password must be supplied. NOINIT is the default.
Your files will keep growing as new backups are being appended.
Also your post does not mention when and how you backup the log. I hope this is only an omission, as log needs to be backed up too.
BACKUP DATABASE [test] TO DISK = N''filePath\test.bak'' WITH DIFFERENTIAL, NOFORMAT, NAME = testdiff',NOINIT, SKIP, REWIND, NOUNLOAD, STATS = 10
in the Statement above I've used NOINIT, naturally the new backup file must be appended to the previous file but because I use the new name for my new backup file, the new file will be created and it won't appended to previous file.
But my problem has been solved. because I had replication on my DB before and after removing it the publication had remained in the SQL instance and there was an active transaction(Replication) on my db so it locks many of the transaction logs and many of my VLFs were active.they were waiting to send to subscriber server.
after removing publication from my SQL instance the VLF files set to 0 and the transaction log file has been shrink So, the differential backup file size were decreased.

Seeking to restore from multiple bak files to a test SQL database

we have a large SQL db that we split into 4 separate bak files in a nightly backup so it can be more easily sent offsite. We use this statement (db names changed)
BACKUP DATABASE [Data] TO
DISK = 'd:\back\data1.bak',
DISK = 'd:\back\data2.bak',
DISK = 'd:\back\data3.bak',
DISK = 'd:\back\data4.bak'
WITH INIT, NOUNLOAD, NAME = 'Data backup', NOSKIP , STATS = 10, NOFORMAT
All four of the backups have the same logical names for the mdf and ldf files in the bak.
I want to be able to restore these four backups into a different database on the server for testing. I found a t-sql script in this post which I think will do this but I am not sure. Can someone help?
I'm thinking I could adapt and run the script as follows:
RESTORE DATABASE Data_test FROM
DISK = 'd:\back\data1.bak',
DISK = 'd:\back\data2.bak',
DISK = 'd:\back\data3.bak',
DISK = 'd:\back\data4.bak'
WITH MOVE 'Prod_Data' TO 'D:\SQLDb\Data_Test1.mdf',
MOVE 'Prod_Data' TO 'D:\SQLDb\Data_Test2.ndf',
MOVE 'Prod_Data' TO 'D:\SQLDb\Data_Test3.ndf',
MOVE 'Prod_Data' TO 'D:\SQLDb\Data_Test4.ndf',
MOVE 'Prod_Log' TO 'C:\SQLtlogs\Data_test1.ldf'
Do you think this would work? And will this test db not conflict with the prod db from which it was restored? Any help would be great, thanks.
OK, I actually got this to work with the GUI for SSMS. All you have to do is choose Tasks, Restore Database, choose from device, then add all four files of the separate bak files, then click OK and do the restore with Overwrite, modifying the file names for mdf and ldf as needed so they are for the test db and not production. SSMS knows the four files are part of the same media set and reassembles them into the mdf and ldf file. Looks like I did not need a script after all.
I used this TRANSACT-SQL command to do almost the same thing you requested. The only difference is that I was only moving each logical file to a single physical file. My command (modified to use your example) looks like this:
RESTORE DATABASE Data_test FROM
DISK = 'd:\back\data1.bak',
DISK = 'd:\back\data2.bak',
DISK = 'd:\back\data3.bak',
DISK = 'd:\back\data4.bak'
WITH MOVE 'Prod_Data' TO 'D:\SQLDb\Data_Test1.mdf',
MOVE 'Prod_Log' TO 'C:\SQLtlogs\Data_test1.ldf'

sql server 2000 backup with agent

I have this script to backup my sql server 2000 database:
BACKUP DATABASE [CRM] TO DISK = N'd:\CRM_BACKUP\crm.bak'
WITH NOINIT, NOUNLOAD, NAME = N'GUY_CRM_BACKUP', NOSKIP, STATS = 10, NOFORMAT
I want the backup to be for several days.
I thought about giving the name of the backup the day of the month
e.g. crm01.bak, crm02.bak.... crm30 or crm31.bak.
How can I do that please?
TIA
Guy
You can set RETAINDAYS to the number of days you wish to keep that backup. Since you are using NOSKIP (and NOFORMAT), SQL Server will not overwrite that backup until it has expired. At that point, you could also institute a naming standard like you are mentioning, or set a maintenance plan to erase backups older than a certain age.

Convert a MS SQL 2008 .mdf file to .bak file

I try to convert a .mdf file to a .bak file, I have been reading this guide: http://forums.asp.net/p/1448416/3870094.aspx
BACKUP DATABASE [NameOfDatabase] TO DISK = N'D:\path\filename.bak' WITH NOFORMAT, NOINIT, NAME = N'NameOfDatabase-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
Replace NameOfDatabase with.... name of your database.
Replace D:\path\filename.bak with place you want to backup with
Replace Name = N database name for cosmetic indexing reasons...
But I get an error message when I run it.
In Visual Studio 2010 in Server Explorer I select Data Connection/myDatabase.mdf and rightclick Stored Procedure and choose "add new stored Procedure". There I write:
BACKUP DATABASE [myDatabase] TO DISK = N'C:\db\dbCopy.bak' WITH NOFORMAT, NOINIT, NAME = N'dbCopy-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
When I select the text and run selection I get this error message:
Executing selected script from mssql:://Home\e1d5110c-dd6f-4d/C:\USERS\myHome\DESKTOP\myPage\APP_DATA\MYDATABASE.MDF/dbo/Stored Procedure/dbo/StoredProcedure1
Database 'myDatabase' does not exist. Make sure that the name is entered correctly.
BACKUP DATABASE is terminating abnormally.
No rows affected.
(0 row(s) returned)
What am I doing wrong? If I change 'myDatabase' to 'C:\USERS\myHome\DESKTOP\myPage\APP_DATA\MYDATABASE.MDF' I get this message:
Database 'C:\USERS\myHome\DESKTOP\myPage\APP_DATA\MYDATABASE.MDF' does not exist. Make sure that the name is entered correctly.
BACKUP DATABASE is terminating abnormally.
No rows affected.
(0 row(s) returned)
You need to attach the database first before you can back it up. Do you have an LDF file as well? You might need one, or it might be happy to build its own afresh - I'm not sure.
The simplest way to do this all is through SQL Server Management Studio. If you don't have it (e.g. you're using SQL Server Express) then you should definitely download it and install it. Log in to your SQL Server instance in Management Studio then
right-click on 'user databases', 'attach' then select your MDF file
right-click on the attached database and 'tasks', 'back up'; use 'remove' and 'add' in the destination box if you want to change the filename.
I know this post has been for a long time but i thought also someone might still need an answer that worked for me, so The bak file is just a backup file of your SQL Server database.
You can download the MS SQL Server Express Management Console (for your version of SQL Server or SQL Server Express) and do this
http://msdn.microsoft.com/en-us/library/ms187510.aspx