Backup of SQL Server 2008R2 database is huge - sql-server

I am backing up a SQL Server 2008 R2 database with the intention of restoring it elsewhere. When I back it up using the backup wizard (right click tasks, backup ) the size of the resulting backup is much larger than I know the database should be (c45Gb when there is only about 5Gb of data)
How can I get a reasonably sized backup created to transfer and restore elsewhere?
Thanks,
Dan

Full backups contain all pages in use plus the part of the log that covers the time span that the backup ran for (approximately). It would surprise me if you generated 40GB of log during a backup of 5GB. At this point I'd check if you really backed up the right database. Or, maybe the destination file already contained other backups.
You say:
I created a smaller backup by going to the options tab on the backup
and set the compression to 'compress backup', I also chose Overwrite
all existing backup sets and Backed up to a new media set name.
Apparently, the existing file already contained data. It is unlikely that compression is responsible for the bulk of the savings.

I created a smaller backup by going to the options tab on the backup and set the compression to 'compress backup', I also chose Overwrite all existing backup sets and Backed up to a new media set name.

Related

SQL Server Copy database to different server

I'm trying to take a copy of a database into another server. I usually been making backup, copy the backup file to another server and restore it. But the backup is 90GB, and the space left after copying the backup to the destination folder is only 26GB. As you probably understand by now I'm not able to restore the database as it doesn't have enough space. So my question is is possible to restore database by replacing backup file? Any other suggestions? Increasing the disc space is not an option as this is just a testing server and the space will be enough after restoring. Thank you
Depending on your SQL Server version have you tried enabling compressing during backup. You would be surprised by how small the backup file can get after compression. Also if your database is set to SIMPLE recovery you could look to reduce the log file size before you backup.
You can find some steps on how to enable compression during backup here
https://sqlbak.com/blog/how-to-configure-backup-compression/

Creating locally database (SQL Server) from remote server for locally test environment

I have to create script which will create the database locally (from database which is on server). Database is 20GB+ and every day is bigger.
What is your advise to do that? I can generate script with all database objects in SSMS, but how operate with data insertion? I mean full script (script which includes data) is not good option. What about one Full Backup and Differetial Backups?
Run generated scripts for all DB objects
Restore Full Backup
Restore Differential Backup
This work is required in order to make possible to test the app locally, on my (another dev's) machine. Thank for every advise!
My advice is to go with a full backup first & get differential backups afterward.
Because a differential backup is not independent and it must be based on the latest full backup of the data. That means there should have a full backup as a base. A differential backup contains only the data that has changed since the differential base. Typically, differential backups are smaller and faster to create than the base of a full backup and also require less disk space to store backup images.
Therefore, using differential backups can save available space and also speed up the process of restoring. At restore time, the full backup is restored first, followed by the most recent differential backup.

Move database from SQL Server 2008 Express to SQL Server 2012

We are looking at migrating one of our databases from SQL Server 2008 Express to SQL Server 2012. The guy that has been taking care of the database says he always does a detach, copy the files to the new server and attach. This takes the database offline of course.
Is there a benefit in doing that vs. right click backup, copy backup files and right click restore on the new server?
Taking a backup should pull everything without taking the DB offline correct?
Is there a recommended best practice for this?
(New to the MS database world)
You could Backup and Restore
You will still have to "un-orphan" sql-users to db-users.
BACKUP DATABASE MyDB TO DISK = 'c:\backups\MyDB.bak' WITH FORMAT
RESTORE DATABASE MyDB FROM DISK = 'c:\backups\MyDB.bak' WITH REPLACE,
MOVE 'MyDB' TO 'd:\sqlfiles\mydb.mdf',
MOVE 'MyDB_Log' TO 'd:\sqlfiles\mydb_log.ldf'
Change the paths however you want.
I'm not sure about best practice, but I have done this more times than I can remember and never had an issue by backing up the DB, taking the old DB offline, and restoring the backup to the new server.
I guess on really high traffic systems you may want to take the DB offline first to ensure nothing changes during your backing up (new records added etc. which would be lost). If you take the DB offline first then you can't back up the DB, so I guess that's when attaching the individual files to the new server becomes necessary as opposed to just restoring the backup.

Difficulty restoring a differential backup in SQL Server, 2 media families are expected or no files are ready for rollforward

I have sql backups copied from server A to server B on a nightly basis.
We want to move the sql server from server A to server B without much downtime, but the files are very large.
I assumed that performing a differential backup and restore would solve the problem with the databases.
Copy full backup from server A to copy to server B (10+gb)
Open SQL Server Managment Studio on server B
Right mouse on databases
Restore Database
Type in the new DB-name
Choose "From Device" and browse to the backup file
Click Okay. This is now resorting the original "full" backup.
Test new db with dev application - everything works :)
On original database rightmouse on DB > Tasks > Backup...
Backup Type = Differential, Backup to disk, add a new file, and remove the old one (it needs to be a small file to transfer for the smallest amount of outage)
Copy the diff backup onto the new db
Right mouse on DB > Tasks > Restore > Database
This is where I get stuck. If I add both the new differential file, and the original backup to the restore process I get an error
The media loaded on "M:\path\to\backup\full.bak" is formatted to support 1 media families, but 2 media families are expected according to the backup device specification.
RESTORE HEADERONLY is terminating abnormally.
But if I try to restore using just the differential file I get
System.Data.SqlClient.SqlError: The log or differential backup cannot be restored because no files are ready to rollforward. (Microsoft.SqlServer.Smo)
Any idea how to do it? Is there a better way of restoring backups with limited downtime?
See 2008 Books Online Performing a Complete Database Restore for details and code.
Perhaps the error is caused by both full and differential backups trying to be restored at once by the backup device specification (may need to be changed).
Do them one at a time (basic idea):
Create tail_log backup.
Restore full first, with NORECOVERY.
Restore differential, with NORECOVERY.
Restore log, with NORECOVERY.
Restore tail_log, with NORECOVERY.
Then, when all done, Restore with RECOVERY.

How to move a database using a differential backup?

I'm using SQL Server 2005.
I need to move a database to a new server with minimum downtime.
Currently my option is to take everything offline, perform a backup, copy the backup to the new server, restore the backup and bring everything back online.
The problem here is that the backup file is about 10Gb, therefore, it takes about 5-10 mins to perform this whole operation.
I've heard of people performing a full backup with everything online and then doing a differential backup so there is less to copy over.
I've taken the full backup, copied that to the new server and restored it. I've then taken a differential backup and copied it to the new server.
The problem is, when I try and restore this backup I get the message "The log or differential backup cannot be restored because no files are ready to rollforward."
I have also tried selecting both the full and differential backup but then I get the error "The volume on device 'D:\FullBackup.bak' is not part of a multiple family media set. BACKUP WITH FORMAT can be used to form a new media set."
Does anyone know what I'm doing wrong and what the easiest way of doing this is?
Thanks
It seems you did not set the NORECOVERY option on the full RESTORE.
You need this option to leave all transactions intact so that you can apply the differential backup later.
If you don't set it, the uncommited transactions get rolled back while restoring the full backup, and the last LSN of the database becomes greater than the first LSN of the differential backup.
Another quick way of doing this is to Detach the database, and then copy the underlying .mdf and .ldf files for your DB straight to the DB, then reattach. Time taken to copy a 10GB file will be much less than the Backup, and it acheives the same thing.

Resources