Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
"restoredb.rb" restores/refreshes MSSQL databases from data bag settings
#
# Cookbook Name:: smashrun
# Attributes:: restoredb
#
# Copyright 2010, Smashrun, Inc.
# Author:: Steven Craig <support@smashrun.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# for reference, this is an example of the JSON inside my chef-server data bags:
# inside databag running_database:
# {"id":"SERVERHOSTNAME","database":"database1,database2,databaseN,master,msdb"}
#
# inside databag database_info:
# {"comment":"main website database","datadrive":"d:","restoredir":"\\MSSQL\\Restore","backupdir":"\\MSSQL\\Backup","transdrive":"e:","transfile":"database1_log.ldf","transinitsize":"256MB","datainitsize":"256MB","datadir":"\\MSSQL\\Data","id":"database1","datamaxsize":"10GB","datafile":"database1.mdf","transmaxsize":"10GB","collation":"SQL_Latin1_General_CP1_CI_AS","transdir":"\\MSSQL\\Logs","restoredrive":"d:","backupdrive":"d:","owner":"development"}
include_attribute "smashrun::createdb"
include_attribute "smashrun::build"
include_attribute "smashrun::store"
include_attribute "smashrun::deploy"
include_attribute "windows::sevenzip"
include_attribute "windows::putty"
# these are standard
default[:restoredb][:author_name] = "#{node[:createdb][:author_name]}"
default[:restoredb][:author_email] = "#{node[:createdb][:author_email]}"
default[:restoredb][:tempdir] = "#{node[:createdb][:tempdir]}"
# templated restoredb rules payload file
default[:restoredb][:basesql] = "restore.sql"
default[:restoredb][:baselog] = "restore.log"
default[:restoredb][:sqlscripts] = "#{node[:createdb][:sqlscripts]}"
default[:restoredb][:restoredir] = "#{node[:createdb][:restoredir]}"
# restore the current production database tag, then apply sql scripts over it
default[:restoredb][:tag] = "#{node[:deploy][:tag]}"
default[:restoredb][:force] = "false"
default[:restoredb][:emailreport] = "false"
# currently only restore / refresh accepted
# refresh intended for recurring dev/qa from production
# restore intended for disaster recovery
if node[:hostname] =~ /^[qQ].+$/
default[:restoredb][:type] = "refresh"
else
if node[:hostname] =~ /^[pP].+$/
default[:restoredb][:type] = "restore"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment