Skip to content

Instantly share code, notes, and snippets.

@alindgren
Created January 17, 2017 15:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alindgren/68dc83d97109bd841a59a197e0edd6ce to your computer and use it in GitHub Desktop.
Save alindgren/68dc83d97109bd841a59a197e0edd6ce to your computer and use it in GitHub Desktop.
Powershell script for grabbing Umbraco Cloud database locally

Notes

Umbraco Cloud uses SQL Azure in the cloud, but for local environments it normally pulls the data down to a local SQL CE database using 'dark magic.' You can, however, pull down the Dev database and restore it to a local SQL Server install. For this, use database.ps1 PowerShell script. You may need to Set-ExecutionPolicy RemoteSigned to run the script. If you are using Windows 7, you may need to configure powershell to use .NET 4 (see http://tfl09.blogspot.com/2010/08/using-newer-versions-of-net-with.html).

In the script, set the location of the folder where you want the DB bacpac file to get saved. Once the file is saved, in SQL Server Management Studio 2014 in the Object Explorer, right click on "Databases" for your local database and select "Import Data-tier Application" to run the wizard. Select the file created from the PowerShell script. Name the new database something convenient.
After the db is created you will need to create a user and configure the website to connect to it.

Credit

I got this from Umbraco Support but I don't see it documented, so I thought I'd share it here.

# This is the path where SQL server is installed
$SqlInstallationFolder = "C:\Program Files (x86)\Microsoft SQL Server\"
# This is where Microsoft.SqlServer.Dac.dll is located -- for WIndows 8.1/10, it may need to be 120 instead of 110
$DacAssembly = "$SqlInstallationFolder\110\DAC\bin\Microsoft.SqlServer.Dac.dll"
# Go to your project on www.s1.umbraco.io and in the "Settings" dropdown choose "Connection details" to get the connection string
$connectionString = "YOUR CONNECTION STRING"
# The name of the database is in the connection string, looks like: `database=abcdefdee`
$databaseName = "DATABASENAME"
# Bacpac files will be written to this directory
$backupDirectory = "C:\db_files\"
# Load DAC assembly.
Write-Host "Loading Dac Assembly: $DacAssembly"
Add-Type -Path $DacAssembly
Write-Host "Dac Assembly loaded."
# Initialize Dac service.
$now = $(Get-Date).ToString("HH:mm:ss")
$Services = new-object Microsoft.SqlServer.Dac.DacServices $connectionString
if ($Services -eq $null)
{
exit
}
# Start the actual export.
$dateTime = $(Get-Date).ToString("yyyy-MM-dd-HH.mm.ss")
Write-Host "Starting backup at $databaseName at $now"
$Watch = New-Object System.Diagnostics.StopWatch
$Watch.Start()
$Services.ExportBacpac("$backupDirectory$databaseName-$dateTime.bacpac", $databaseName)
$Watch.Stop()
Write-Host "Backup completed in" $Watch.Elapsed.ToString()
@thantshweaung
Copy link

We have a database which we developed locally before using Umbraco cloud. How we can restore that local database to Umbraco cloud? Would you help with us because we didn't hear any support from Umbraco HQ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment