Tag: syndicated

  • Speaking Stats

    I was updating my speaking schedule and CV, trying to get an idea of what might be planned for 2015. As I was doing so, I decided to do a quick count of events and talks to see where I was last year. Last year was tough, and I need to find a way to better balance life and travel in 2015.

    What I found surprised me. While I attended 26 events and gave 46 talks, that was down from the previous year. The numbers are:

    Year Events Talks
    2008 2 2
    2009 2 2
    2010 7 10
    2011 13 21
    2012 17 33
    2013 30 54
    2014 26 45

    I found 2014 to be a hard travel year, with quite a few trips out of town. However I think the main problem was that much of my travel was compressed. I didn’t travel for a few long stretches, including a 6 week stretch when I had surgery, which meant that other travel was compacted into a few short periods. Sept and Oct were particularly hard.

    I was surprised at how few events I’d had in 2010 and prior. I would have thought my load increased more linearly, but it hadn’t. Certainly in 2010, my daughter was still in elementary school, my wife was working full time for a corporation and traveling quite a bit, my middle son was starting middle school, and my oldest was graduating. 2011 freed up some time, and made it easier for me to travel. 2012 was the year when my life left her job, making things much easier for me to schedule trips.

    I suspect 2015 will be more like 2014, though I hope to spread the travel out. I’ll be speaking in at least one new country, which is exciting for me.

  • Powershell – Copy the Latest Backup

    I got an email recently where someone asked me how they can refresh a dev environment with Powershell. I guess I’d written something about this in 2009, though that would have been for testing as Red Gate had already banned me from development on SQLServerCentral by that time.

    I dug around and came up with a few partial scripts and cleaned them up for these posts. This post will look at getting the backup and a later one will examine the restore.

    Finding the Latest Backup

    I’ll assume that you make backups on a known path somewhere. My philosophy is that I want the machines to stand alone as much as possible. That means that I don’t want the source machine (the one making the backup) to be working on refreshing the backup elsewhere. I want a pull system.

    For a high level overview, this process looks like this:

    • Search the backup path for files matching a pattern.
    • Find the most recent one, based on date.
    • Copy that most recent file to another location.

    For the sake of consistency and easy, I want to copy the file with the same destination name every time. That will simplify my restore process, which I could easily then do in T-SQL.

    Let’s examine how to do this. I’ve got a folder with a few backups in it.

    backuplatest

    For my PoSh, I’ll start by setting a variable to the path.

    $backuppath = "D:\SQLServer\MSSQL11.MSSQLSERVER\MSSQL\Backup" 

    Once I have this, I can now look for the files in this path. To do that, I’ll use Get-Children.

    get-childitem -path $backuppath

    This will return to me a list of the files. That’s what I want, but I want to limit the files to a pattern. In this case, I’m looking for .bak files, from the EncryptionPrimer database. All of these

    There’s nothing special about what I do that’s not contained in plenty of places. I don’t have this running on an environment currently as someone else manages that process, but here’s the process I’ve followed in the past:

    • Find the latest backup (whatever the date) in the source folder.
    • Copy this with a set name to the destination folder, overwriting previous backups with the same name.
    • Restore the known name to the development database, moving files as needed.

    I’ll go through each of these steps in my PoSh script.

    Find the Latest Backup

    This is fairly easy. I’ll use the Get-ChildItem method, which I found in a StackOverflow post. I’ll use a variable for the path I need, and then check the path.

    $backuppath = "D:\SQLServer\MSSQL11.MSSQLSERVER\MSSQL\Backup"

    get-childitem -path $backuppath

    That works well, but since I’m building a process for a specific backup type, I’ll add a filter.

    $backuppath = "D:\SQLServer\MSSQL11.MSSQLSERVER\MSSQL\Backup"

    get-childitem -path $backuppath -Filter "EncryptionPrimer*.bak"

     

    To find the latest backup, we’ll pipe the output through the Where-object filter, removing folders. Then we use sort-object to order things by creation date and select-object to get just the one file.

    $backuppath = "D:\SQLServer\MSSQL11.MSSQLSERVER\MSSQL\Backup"

    get-childitem -path $backuppath -Filter "EncryptionPrimer*.bak" |

        where-object { -not $_.PSIsContainer } |

        sort-object -Property $_.CreationTime |

        select-object -last 1

     

    The last part of the script is the copy-item command, which is again the recipient of piped output. We give a standard name, and path (another variable).

    $backuppath = "D:\SQLServer\MSSQL11.MSSQLSERVER\MSSQL\Backup"

    $destpath = "d:\SQLServer\Backup"

    get-childitem -path $backuppath -Filter "EncryptionPrimer*.bak" |

        where-object { -not $_.PSIsContainer } |

        sort-object -Property $_.CreationTime |

        select-object -last 1 | copy-item -Destination (join-path $destpath "EncryptionPrimer.BAK")

    Once this is done we can restore things. I learned how to do this from PoSh using this post: http://stuart-moore.com/day-11-31-days-sql-server-backup-restore-using-powershell-basic-restore/

    However, since I have a standard backup file name, I’d probably do this in T-SQL and set a job that I can just run anytime. It’s simpler and easier, and since most of the time I’d want to do this from SSMS, a job works well.

    Here’s the PoSh script.

    Import-Module "SQLPS" -DisableNameChecking

    $sqlsvr = New-Object -TypeName  Microsoft.SQLServer.Management.Smo.Server("JollyGreenGiant\SQL2012")

    $BackupFile = "D:\SQLServer\Backup\EncryptionPrimer.BAK"

    #

    #echo ""

    #echo "Databases"

    #echo "———"

    #foreach ( $db in $sqlsvr.Databases) { write-host $db.name }

    echo " "

    echo "Begin Restore"

    echo "============="

    $Restore = New-Object "Microsoft.SqlServer.Management.Smo.Restore"

    $Restore.NoRecovery = $false

    $Restore.ReplaceDatabase = $true

    $Restore.Action = "Database"

    $Restore.PercentCompleteNotification = 10

    $BackupDevice = New-Object ("Microsoft.SqlServer.Management.Smo.BackupDeviceItem") ($BackupFile, "File")

    $Restore.Devices.Add($BackupDevice)

    $RestoreDetails = $Restore.ReadBackupHeader($sqlsvr)

    $logicalFileNameList = $Restore.ReadFileList($sqlsvr)

    $Restore.Database = $RestoreDetails.Rows[0]["DatabaseName"]

    foreach($row in $logicalFileNameList) {

        $RestoreDBFile = new-object("Microsoft.SqlServer.Management.Smo.RelocateFile")

        $RestoreDBFile.LogicalFileName = $row["LogicalName"]

        $RestoreDBFile.PhysicalFileName = $row["PhysicalName"]

        $Restore.RelocateFiles.Add($RestoreDBFile)

            }

    $Restore.SqlRestore($sqlsvr)

    write-host ("Completed the Database Restore operation on server for Database " +  $RestoreDetails.Rows[0]["DatabaseName"] + " on server $server")

     

    That’s it. I ran this a few times, and it worked well. A handy script to get the last backup and have it ready in a dev/test environment.

  • Quick Audio Switching

    I’ve got a semi complicated desktop setup, with multiple monitors, lots of USB stuff, and a few ways to record and listen to sound. I hadn’t thought of things as complex, especially with regards to audio, but between recording podcasts, having regular video conferences, and the speakers I added to my machine, I found the need to control where my audio goes in and out of.

    The other day I was waiting for a conference call to start on Skype and was listening to an interview through my computer. I’d plugged in a USB headset for the call, but the interview (Flash-based web page), came through the speakers. I’ve gotten used to redirecting audio easily from the speakers to headphones to Bluetooth devices, but I wasn’t sure how to do this in Windows. I messed with the audio mixer a bit, but didn’t see anything.

    I did a bit of searching and ran across this post on Superuser. I decided to blog briefly in the hopes that I’ll remember this process for next time.

    The long and short of it was that I needed to right click the audio speaker icon.

    recorduadio1

    I could then select Playback devices. This allows me to see the setup, not just the volume. I got the Control Panel app, with all my devices listed. I can also see the recording devices.

    recorduadio2

    From here, if I right click a device, in this case, the USB headset, I can select "Set as Default".

    recorduadio3

    Once I did this, the audio for the interview came through on the headset. I could listen and when my Skype call came in, it cut out and I could continue on with work.

    This is especially handy for recording, as I’ve had the wrong device setup for recording at times because I’ve expected the default to be used.

  • SQL Konferenz

    I’ve spoken at lots of events, but all in the US and the UK. Next year I get my first talk outside of those locations, going to the SQL Server Konferenz near Frankfurt, Germany.

    The agenda is up, and I’ll be talking testing and tSQLt there, and it’s cool to see my name up there. I’m also glad to see the UK flag there to note I’ll be presenting in English.

    konferenz

    Fingers crossed that things go well.