Avoid 3rd Party management software. Backup software doubly so.
Category: MS SQL 2017
Differential backup / restore using SQL Safe
I wanted to improve a backup / restore sql-job that populated a Reporting Server every night. I felt it would be quicker if it did a weekly Full backup and daily Diff backups.
The 3rd-party backup software was “SQL Safe Backup” from Idera.
I used this code on the Production Server …
--BackupDBA.sql -- FULL Backup if Friday IF (SELECT DATEPART(dw, GETDATE())) = 6 BEGIN EXEC [master].[dbo].[xp_ss_backup] @database = 'DBA', @filename = '\\ReportingServer\m$\DBA_Full.safe', @backuptype = 'Full', @overwrite = 1, @verify = 1; END; -- DIFF Backup EXEC [master].[dbo].[xp_ss_backup] @database = 'DBA', @filename = '\\ReportingServer\m$\DBA_Diff.safe', @backuptype = 'Diff', @overwrite = 1, @verify = 1;
… and this code I scheduled a few hours later on the Reporting Server …
--RestoreDBA.sql
-- First, kill any connections
DECLARE @kill VARCHAR(8000) = '';
SELECT @kill = @kill + 'kill ' + CONVERT(VARCHAR(5), spid) + ';'
FROM [master].[dbo].[sysprocesses]
WHERE dbid = DB_ID('DBA')
AND spid > 50;
EXEC (@kill);
-- Restore FULL
EXEC [master].[dbo].[xp_ss_restore]
@database = 'DBA',
@filename = 'M:\DBA_Full.safe',
@backuptype = 'Full',
@recoverymode = 'norecovery',
@replace = '1';
-- Restore DIFF
EXEC [master].[dbo].[xp_ss_restore]
@database = 'DBA',
@filename = 'M:\DBA_Diff.safe',
@backuptype = 'Diff',
@recoverymode = 'recovery',
@replace = '1';
Finally, I added a step on Reporting to repair the orphaned user-accounts …
USE [DBA] GO EXEC sp_change_users_login 'Auto_Fix', 'ReportingLogin'; EXEC sp_change_users_login 'Auto_Fix', 'LinkedServerLogin'; GO
TempDB Autogrowth
I was shocked to find TempDB was the most often autogrown in our environment – and changing them by hand soon got old.
Here’s my global script to set them to best-practice values, that will only change files that exist, and will fail if the specified size is less than the current size (IE: it fails safe).
--tempdb_autogrowth.sql -- report size and growth select name, size*8/1024 [sizeMB], growth*8/1024 [growthMB] from master.sys.master_files where db_name(database_id) = 'tempdb' order by physical_name -- resize datafile(s) to 256MB & logfile to 128MB USE [master] GO begin try ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'tempdev', SIZE = 262144KB , FILEGROWTH = 262144KB ); ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'tempdev2', SIZE = 262144KB , FILEGROWTH = 262144KB ); ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'tempdev3', SIZE = 262144KB , FILEGROWTH = 262144KB ); ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'tempdev4', SIZE = 262144KB , FILEGROWTH = 262144KB ); ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'templog', SIZE = 131072KB , FILEGROWTH = 131072KB ); end try begin catch end catch