Search

Fast Restores with Sql Server Snapshots

Friday 18 December 2015

Using Backup/Restore to reset you data is ok but it can take a while. Snapshots are a much faster alternative. On my system a 20Gb snapshot restores in less than 10 seconds.

What are snapshots
A database snapshot is a readonly view of a database at the time the snapshot was created. The exist as a database on the server – you can find them in ‘Database Snapshots’ in the Sql Managment Studio object explorer. You can use them for reporting but here we are creating them, then restoring them over the main database.

Creating snapshots
Here’s the script to create a snapshot. It doesn’t need much explanation…

If db_id('DemoSnapshot') is Not Null
Begin
    Drop Database DemoSnapshot
End


CREATE DATABASE DemoSnapshot ON ( NAME = DemoDatabase, FILENAME =  'E:\TempBackups\Demo.ss') As Snapshot of DemoDatabase

If your database filename doesn’t match the database name you might get an error that says all files must be specified. In that case you need to pass the file name to the Name parameter.

Restoring snapshots
The script to restore the snapshot is simple as well. It closes existing connections by putting the database into single user mode, restores the snapshot, then puts the database back into multi user mode.

ALTER DATABASE DemoData SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

RESTORE DATABASE DemoData From Database_Snapshot = 'DemoSnapshot'
GO

ALTER DATABASE DemoData SET MULTI_USER
GO
 

That’s it, run the restore script whenever you want to put the database back to the saved state.

Quick Fix: Android Emulator is offscreen

Thursday 16 April 2015

image
I’ve been having an annoying problem when the title bar for my Android emulator is off the top of the screen in Windows so I can’t move it around. I’ve found a couple of fixes…
1 – Hove over the icon on the TaskBar until a preview appears. Right click on the preview and select move. Then you can move the emulator with the cursor keys.
2 – Try using a different skin. I’ve found switching to no skin will bring the emulator back on screen and then I can switch it back to my normal skin with no problems.

An Autohotkey Timer Function

Sunday 25 January 2015

Here's a handy time function for use with autohotkey, it waits for the specified number of seconds and shows a countdown on the screen.

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

TimerSleep(Time)
{
    Countdown := Time

    Loop, %Time%
    {
        SplashTextOn, , 30,Sleeping, %Countdown%  
        Sleep, 1000
        Countdown := Countdown - 1
    }

    SplashTextOff
    return 0
}