Create database backup, ignore column - sql

I'd like to create a database backup using SSMS.
The backup file will be a .bak file, but I would like to ignore 1 column in a certain table, because this column isn't necessary, but it takes up 95% of the backup size.
The column values should all be replaced by 0x00 (column type is varbinary(max), not null).
What's the best way to do this?
FYI: I know how to generate a regular backup using Tasks => Back Up..

There is a long way of doing what you ask. Its basically create a new restored database, remove the non required data and then do a new backup again.
Create a Backup of the production database.
Restore the backup locally on production with a new name
Update the column with 0x00
Shrink the database (Shrink is helpful when doing a restore. This wont reduce the bak file size)
Take the backup of the new database (Also use Backup Compression to reduce the size even more)
Ftp the bak file
If you only needed a few tables, you could have used bcp but that looks out of the picture for your current requirement.

From SQL Server native backups, you can't. You'd have to restore the database to some other location and then migrate usefull data.

You can create a copy of your table without the column and backup using filegroups https://msdn.microsoft.com/en-us/library/ms191539(SQL.90).aspx

Related

Why Database backup size differs when backing up from Query and SSMS?

I am confused with the size of the file I backup with SSMS and Query.
If I create a file from SSMS in its default folder something like "C:\Program Files\Microsoft SQL Server\MSSQL14.NAMEDINSTANCE\MSSQL\Backup" the outfile say Db1.bak is about 198292 KB
Same database if I backup with the query "backup database Db1 to disk='D:\Db1.bak' the file size is just 6256 KB
Sometimes the other database say Db2 gives the same filesize i.e 6256 KB(Both Db1 and Db2 have identical(same) schemas just data in it are different.)
And backup with SSMS gives 33608 KB which seems satisfactory.
I also tried verifying all database in SSMS like this RESTORE VERIFYONLY FROM DISK = 'D:\BACKUP\Db1.bak'
GO and result gives valid in every database check.
I also tried deleting Db1 from SSMS and restoring the less KB file and checked some data of few tables (Not All) and it seems showing all data in tables properly but the filesize dissatisfies me.
Thank You.
I suspect that,like initially mentioned, you have compression on my
default, and using the GUI, with the settings is not making use of
that (and that if you selected to Compress in the GUI, you'd get a
similar size)
If the server option backup compression default is on, even if you don't mention it in your backup command, compression will be applied. So in both cases there would be compressed backup. But it's easy to see, just run this command for both backups:
restore headeronly
from disk = 'here_the_full_path_with_filename';
In the 5th column you'll get the flag if your backup is compressed.
But the cause of this difference is another one, and you'll see it when run restore headeronly: you made multiple backups to the same file.
You used backup command with noinit from SSMS, and the same file name, so now this file contains more than one backup, and restore headeronly will show them all.

copy databases using log files

I have a database which is needed to replicate.
I tried with copy database scenario but after 1 day it was failed.
I tried using to create .bak file but no enough space on disk....
I need an alternate scenario to achieve this..
Can I Create a new database and replace its mdf and ldf files with original database and rename files...?
The fastest and the easiest way - to use an additional disk with more free space.

Backup SQL Server database using WITH FORMAT

I'm having a bit of trouble understanding the purpose of the WITH FORMAT option of the SQL Server BACKUP DATABASE command.
Using the MSDN example:
USE AdventureWorks2012;
GO
BACKUP DATABASE AdventureWorks2012
TO DISK = 'Z:\SQLServerBackups\AdventureWorks2012.Bak'
WITH FORMAT,
MEDIANAME = 'Z_SQLServerBackups',
NAME = 'Full Backup of AdventureWorks2012';
GO
I understand this deletes any existing backups and creates a new one.
If I was to omit the WITH FORMAT line, and I already had a backup at Z:\SQLServerBackups\AdventureWorks2012.Bak, what does this mean to my backup?
Is it incremental or does it overwrite with a full one?
It's a full backup, essentially appended to the file if it exists already, you'll see a File number 2 reference when you run it, and you'll see the backup file double in size. Each backup is independent of each other and either can be restored.

SQL Server 2005 backup and restore

I have two backup files
1) is named 'backup.sql' with a bunch of SQL defining TABLES
2) is named 'backup' with a bunch of encoded data, which I believe are the ROWS
I need to restore these TABLES + ROWS, but all I am able to figure out is how to restore the tables.
Any tips on dealing with these files? It's the first time I ever deal with SQL Server.
The backup process would not create a file with actual SQL statements, it would create a binary file. So #1 is not a backup file (it's probably a script someone saved to re-create the schema).
I would try to use SQL Server Management Studio to restore the second file and see what happens. I don't think it will allow you to restore an invalid file, but I would take some basic precautions like backing up the system first.
What is the extension for the 'backup' file? Is the filename backup.bak? If you have a backup file created by sql server then it 'should' contain the logic to create both the tables and restore the data, but it could depend on how the backup was created.
---Edit
It is possible for a .SQL file to contain data values as well as the logic to create the tables/columns for a database. I used to run backups of a MySql database in this way a long time ago...it just is not seen very often with SQL server since it has built in backup/restore funcationality.
Seems unlikely they would export all the rows from all tables into CSV file, and given you said it looks encrypted, it's making me think that's your actual backup file.
try this, save a copy of the "backup" file, rename it to backup.bak and run this from SQL Server Management Studio
restore filelistonly from disk='C:\backup.bak'
(assuming your file is saved on the root of the C: drive)
Any results/errors?

Selectively restoring a database

I have been using this query:
BACKUP DATABASE RentalEase
TO DISK = 'C:\RentalEaseBackup\RentalEase.bak'
WITH COPY_ONLY;
GO
To backup my database. Someone deleted something so now I have to restore it from a previous point in time, however I don't want to overwrite new changes (other than the deletions).
What I was thinking I could do it attached the backup to the SQL Server as a new database and then perform the necessary queries to move the few deleted rows over. However, it won't attach the RentalEase.bak file because it says it isn't a primary database file.
How can I attach the database backup so I can run the SQL queries against it?
You have to RESTORE the DB, you can't attach a backup file
RESTORE DATABASE TestDB
FROM DISK = 'c:\Northwind.bak'
WITH MOVE 'Northwind' TO 'c:\test\testdb.mdf',
MOVE 'Northwind_log' TO 'c:\test\testdb.ldf'
Full syntax here
Restore the database to a different database name, and then you can do whatever you want between the two databases (good luck!)
create a new database named RentalEase2, A restore would look like this
RESTORE DATABASE [RentalEase2] FROM DISK = N'C:\RentalEaseBackup\RentalEase.bak'
WITH FILE = 1, NOUNLOAD, STATS = 10
GO