Search This Blog

Showing posts with label Backup. Show all posts
Showing posts with label Backup. Show all posts

Tuesday, 2 October 2012

Quick dated copy of folder

A double click on the .bat file for a copy of the data in a dated folder

dobackup.bat


set stamp=%date:~6,4%%date:~3,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,2%_bak
set source="c:\data"
set target=c:\data_backups\%stamp%
robocopy %source% %target% /XD temp /E > %target%.log


robocopy flags:
/XD  - exclude directory (in this case temp files that I don't want to backup)
/E  - copy (not mirror)

Monday, 5 March 2012

SQL Server database scripted restore from backup

SQL Server scripted restore - this is a bit aggressive as it will boot out users and lock the database, so it's best used in an out of ours scheduled basis.


USE [Master];
GO


ALTER DATABASE [MyDatabase] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO


RESTORE DATABASE [MyDatabase] FROM  DISK = N'C:\BAK\MyDatabase.BAK' WITH FILE = 1, MOVE N'MyDatabase_Data' TO N'C:\DB\MyDatabase_2012_01_01.MDF',  MOVE N'MyDatabase_Log' TO N'C:\DB\MyDatabase_2012_01_01.LDF',  NOUNLOAD,  REPLACE,  STATS = 10
GO


ALTER DATABASE [MyDatabase] SET MULTI_USER;
GO


ALTER DATABASE [MyDatabase] SET RECOVERY SIMPLE;
GO


USE [MyDatabase];
GO


DBCC SHRINKFILE (MyDatabase_Log, 64);
GO


ALTER DATABASE [MyDatabase] SET RECOVERY FULL;
GO

Note: STATS indicates the percentage completion that a progress event is raised.  I've not tried it, but I gather these can be captured if you're running this script as an SMO object within .net