Tag Archives: backup

PS script to get SQL version from BAK file

Quite unpleasant thing about MS SQL Server database backup files it that you can’t restore them on an older version of SQL Server (it seems that even if you really want to create such BAK file it is not possible), moreover this is valid not only for major versions but also for things like R2, meaning you can’t restore BAK file created in SQL Server 2008 R2 on SQL Server 2008 Server (non-R2).

Just to save my time trying to restore BAK files against wrong versions of SQL Server I created this script:

It will allow you to retrieve SQL version from BAK file headers and compare it with your server SQL version. Specify path to your BAK file and check the output – if BAK file SQL version is newer that your server version then BAK file can’t be restored on this server. Sample script output can be found below:

It tells you that backup was taken on SQL Server 2012 SP3, while you run SQL Server 2012 SP2. Once you install SP3 for SQL Server script output will change to this:

Once two numbers match (or your SQL Server version number is higher than BAK file SQL version number) you are ready for backup restore 🙂 I’ve also added to this script comparison and output of its result, along with prompt for BAK file name and location:

Please follow and like us:

How to export / and import SharePoint 2013 sites, lists, or libraries with PowerShell

For copying individual items across your SharePoint 2013 environments or making single item backups of  sites, lists, or libraries you may employ following PowerShell commandlets: Export-SPWeb and Import-SPWeb.

Here is a basic example of performing library export and further import using those cmdlets. First, export:

Export-SPWeb -Identity http://sitename.domainname.com -ItemUrl /Library_Name -path "c:\Library_Name_Backup.cmp"

The only thing which may cause some difficulties is how to correctly specify Identity and URL parameters, as if you are going to look at the URL of SharePoint library when it is opened in browser and try to use it – it won’t work out. Usually URL of a library accessed in browser looks similar to this:

http://yoursite.yourdomain.com/_layouts/15/start.aspx#/Your_Library_Name/Forms/AllItems.aspx

You have to take parts highlighted in bold for Export-SPWeb as a values for Identity and ItemUrl parameters including slash symbol in front of library name, otherwise it won’t work. E.g. if you omit slash in the beginning of URL parameter value Export-SPWeb will throw following (not quite self explanatory) error at you:

Export-SPWeb : <nativehr>0x80070057</nativehr><nativestack></nativestack> At line:1 char:1

So type things carefully 🙂

Next is import:

Import-SPWeb http://yoursite.yourdomain.com -Path c:\Library_Name_Backup.cmp -UpdateVersions Overwrite

Use of this 2 cmdlets will help you to create item level backups for sites, lists and libraries in SharePoint 2013. By the way for those who wondering what CMP file extension stands for – this is abbreviation for “Content Migration Package”.

And if you want to run these commands from regular PS session without starting SharePoint Management Shell be sure to load SP PS snapin using script below:

Please follow and like us: