Browsing MS SQL Server db backup (.bak) file in linux locally without SSMS or SQLCMD or without online tools

Untitled

Imagine you only have a copy of MS SQL Server database backup (*.bak) file with no other tools for accessing it like SSMS(SQL Server Management Studio),SQLCMD,SQL-Server etc preinstalled on your machine and you would like to browse the content of the file without these tools now.

  • Because installing and setting all of them up would cost a lot of time and energy, and
  • You certainly don’t want to give out these DATA with potential bussiness value to a third party websites like rebasedata.com etc etc and
  • Even online tools have file size limitations, which should require extra dollars to work on huge files(>10MB).

Well there is a hack, a way to achieve this if you are looking to browse only db schema and no data.

Simply open the backup(*.bak) file with vim or any other plain text editor:

vim MS-SQL-db-filename.bak

At this point, you are going to see something like this:

TAPE^@^@^C^@<8c>^@^N^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^B^@<87>^E<85>i<8c>^E^@^@^@^A^@^@^@^A^@^C^@^@^@^@^@^@^@^@^@^@^@^@^@,^@^^@^@^D^@^R^_<8e>lµL^AM^@i^@c^@r^@o^@s^@o^@f^@t^@ ^@S^@Q^@L^@ ^@S^@e^@r^@v^@e^@r^@^@^@^@^@^@^@RAID^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@;^E³j$^O|µÜK¯ñC<89><86>𳺭^@^@ð^A^@^A^@^A^@^@^@^@^@^A^@^@^@SPAD^@^@^@^@&^C^@^@^@^@^@^@^@^@^@^@4^W^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

But don’t panic. Search words like “Create”, “Table”, “Procedure”, “Trigger” (incase-sensitive).

And you will find texts like:


 `CREATE PROCEDURE [dbo].[FL_GetLoanDetails]     ^M  
 -- Add the parameters for the stored procedure   
 -- here    ^M  
  @TraceNo int,    ^M  
  @LoanStatus int,    ^M  
  @MPLID nvarchar(100),    ^M  
  @StopLoan int, ^M  
  @LoanCatId int,^M  
  @LoanTypeId int^M  
      ^M  
AS    ^M  
BEGIN    ^M  
 -- SET NOCOUNT ON added to prevent extra result sets  
 -- from    ^M  
     ^M  
-- FL_GetLoanDetails 0,2,'',2, 0, 0    ^M  
     ^M  
    declare @PStartDate nvarchar(20)= null^M  
    declare @PEndDate nvarchar(20)= null^M` 

It’s normal you may find lots of ^M’s at the end of every line.
It indicates the file had been taken backup on windows machine and they denote DOS encoding new line endings.
Copy and paste the whole code snippet into a new plain text editor window and these ^M’s should be gone.

Resulting in a full readable sql code snippet.

No comments:

Post a Comment