Skip to main content

Posts

Showing posts with the label Zip

More DOS batch fun

Recently I needed to create a simple way to backup alot of website's log files. The directory structure is such: C:\DemoSites\ | |----\Demo1 | | | |-----\Logs | |----\Demo2 | | | |-----\Logs | |----\Demo3 | | | |-----\Logs | |----\Demo4 | | | |-----\Logs | ... etc ... So I need to backup the log files inside each "Logs" directory, in a loop... Here is the batch file that takes care of it: 01: @ECHO OFF 02:   03: :: Get Today's Date in YYYYMMDD Format... 04: for /F "tokens=2-4 delims=/ " %%a in ( 'date/t' ) do (set datevar=%%c%%a%%b) 05:   06: :: For each subdirectory of C:\DemoSites, Zip all log files in their Logs directories... 07: for /D %%d in (C:\DemoSites\*) do ( 08: if exist %%d\Logs ( 09: for /F "tokens=5 delims= " %%k in ( 'dir %%d\..\.' ) do ( 10: if exist %%d\..\%%k\Logs\*.* ( 11: if not exist...

Backup Databases in a loop...

Note: This applies to Microsoft SQL Server 2005/2008...     Ever get sick of having a different SQL Job for each database backup? I created this method for backing up all databases (filtered) in a cursor. Just create a job with this as the Step and give the Job a schedule... 01: DECLARE @dbName varchar (50) 02: DECLARE @BKPDate varchar (10) 03: DECLARE @sql nvarchar (1000) 04: SET @BKPDate = replace ( convert ( varchar (10), getdate (), 102), '.' , '' ) 05: DECLARE bkpCursor CURSOR FOR 06: 07: /* only backup non-system databases */ 08: select [Name] from sys.databases where [owner_sid] <> 0x01 09: 10: OPEN bkpCursor 11: FETCH NEXT FROM bkpCursor INTO @dbName 12: IF @@FETCH_STATUS = 0 13: BEGIN 14: WHILE ( @@FETCH_STATUS = 0) 15: BEGIN 16: set @sql = 17: ' BACKUP DATABASE ' + @dbName + 18: ' TO...