My dbamohsin Blog: 2012 stats in review

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

19,000 people fit into the new Barclays Center to see Jay-Z perform. This blog was viewed about 63,000 times in 2012. If it were a concert at the Barclays Center, it would take about 3 sold-out performances for that many people to see it.

Click here to see the complete report.

Empty out files in VBS

As part of our replication setup from SQL Server to Oracle, when we initially create a snapshot, we manually empty out all idx, sch and pre files. This is because we setup the oracle environment ourselves and dont want to use the microsoft generate code as it would cause the snapshot to fail.

I Needed a script to quickly clear out all IDX, SCH & PRE files, so made this in VBS this morning.

Dim objFSO Dim strDirectory Set objFSO = CreateObject("scripting.filesystemobject") strDirectory = "C:\VBS" CheckFolder (objFSO.getfolder(strDirectory)) '============================================================================ Sub CheckFolder(objCurrentFolder) Const ForWriting = 2 Dim objFile Dim stridx Dim strpre Dim strsch Dim strTemp stridx = ".idx" strpre = ".pre" strsch = ".sch" For Each objFile In objCurrentFolder.Files strTemp = Right(objFile.Name, 4) If UCase(strTemp) = UCase(stridx) or UCase(strTemp) = UCase(strpre) or UCase(strTemp) = UCase(strsch) Then Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(objFile.Name, ForWriting) objFile.Write "" objFile.Close End If Next End Sub '============================================================================

DOS – Compressing and uploading files to FTP

Problem – I had been asked to upload a database backup to a FTP location on the first sunday of every month for one of our partner companies. I decided to add some logic into the process to do this automatically via a scheduled task, for which the thought process and commands are listed below.

O/S: Windows Server 2000

Solution: The solution was to first backup the database via SQL CMD (Not discussed here) and then to create a batch file which zipped up the backup, connected to the FTP location and uploaded the file. This was later enhanced by adding a 3 attempt policy so that it would try again if the upload failed.

zip_backups.bat

To zip up the backup file, a program called INFO-ZIP is used which allows command line compression – http://www.info-zip.org/

To Send the Mail a program called mailsend is used – http://www.muquit.com/muquit/software/mailsend/mailsend.html

The Retry is figured out by searching the ftp output log for a specific phrase which only occurs when a successful upload happens. This is then turned into logic using standard errorlevel syntax.

REM ##############################################################################
REM ## AUTHOR: MOHSIN PATEL                                                        ##
REM ## Developed to automatically zip up backup files for transfer                 ##
REM ## Date: 21/06/2010                                                            ##
REM ## Changes made on 05/01/2011 to add retry counts and to split up            ##
REM ## each backup job                                                            ##
REM ##############################################################################

set countcar=1
echo Starting MY_DB1 %date% %time% > MY_DB1_ftpout.log
echo. >> MY_DB1_ftpout.log
echo ========================================================= >> MY_DB1_ftpout.log

set countlights=1
echo Starting MY_DB2 %date% %time% > MY_DB2_ftpout.log
echo. >> MY_DB2_ftpout.log
echo ========================================================= >> MY_DB2_ftpout.log

:ftpcar
rm MY_DB1.zip >> MY_DB1_ftpout.log
E:\Backup_transfers\INFO-ZIP\zip.exe -q -r MY_DB1 MY_DB1.bak >> MY_DB1_ftpout.log
FTP -i -s:ftpconnect_CAR.txt >> MY_DB1_ftpout.log

find "Transfer OK" MY_DB1_ftpout.log
set error=%errorlevel%

if %error%==0 goto sendsuccesscar

if %countcar%==3 goto sendfailcar
else
goto retrycountcar


:sendsuccesscar
MAILSEND -d domain.co.uk -smtp 0.0.0.0 -t you@ftp.co.uk -f me@ftp.co.uk -sub "BACKUPS COPY COMPLETE - SUCCEEDED - MY_DB1" -m MY_DB1_ftpout.log >> MY_DB1_ftpout.log
goto ftplights

:sendfailcar
MAILSEND -d domain.co.uk -smtp 0.0.0.0 -t you@ftp.co.uk -f me@ftp.co.uk -sub "CAP BACKUPS COPY COMPLETE - FAILED - MY_DB1" -m MY_DB1_ftpout.log >> MY_DB1_ftpout.log
goto ftplights

:retrycountcar
set /A countcar+=1
echo. >> MY_DB1_ftpout.log
echo ****************** Retrying attempt %countcar% ******************* >> MY_DB1_ftpout.log
echo. >> MY_DB1_ftpout.log
echo Starting: %date% %time% >> MY_DB1_ftpout.log
echo ========================================================= >> MY_DB1_ftpout.log
goto ftpcar


:ftplights
rm MY_DB2.zip >> MY_DB2_ftpout.log
E:\2ndByte_Backup_transfers\INFO-ZIP\zip.exe -q -r MY_DB2 MY_DB2.bak >> MY_DB2_ftpout.log
FTP -i -s:ftpconnect_LIGHTS.txt >> MY_DB2_ftpout.log

find "Transfer OK" MY_DB2_ftpout.log
set error=%errorlevel%

if %error%==0 goto sendsuccesslights

if %countlights%==3 goto sendfaillights
else
goto retrycountlights

:sendsuccesslights
MAILSEND -d domain.co.uk -smtp 0.0.0.0 -t you@ftp.co.uk -f me@ftp.co.uk-sub "CAP BACKUPS COPY COMPLETE - SUCCEEDED - MY_DB2" -m MY_DB2_ftpout.log >> MY_DB2_ftpout.log
goto end

:sendfaillights
MAILSEND -d domain.co.uk -smtp 0.0.0.0 -t you@ftp.co.uk -f me@ftp.co.uk -sub "CAP BACKUPS COPY COMPLETE - FAILED - MY_DB2" -m MY_DB2_ftpout.log >> MY_DB2_ftpout.log
goto end

:retrycountlights
set /A countlights+=1
echo. >> MY_DB2_ftpout.log
echo ****************** Retrying attempt %countlights% ******************* echo. >> MY_DB2_ftpout.log
echo. >> MY_DB2_ftpout.log
echo Starting: %date% %time% >> MY_DB2_ftpout.log
echo ========================================================= >> MY_DB2_ftpout.log
goto ftplights

:end

ftpconnect file

open ftp2.ftp.com
USERID
p@ssw0rd
bin
delete MY_DB1.zip
put MY_DB1.zip
disconnect
bye

Embed Flash into WordPress.com…

Useful link that i found which lets you embed flash into a free wordpress blog

Embed Flash

Raising money for the British Heart Foundation….

Hi Everyone,

After months of exercising and jogging on a casual basis, I’ve finally plucked up the courage to do it for a cause! I am going to be running the Manchester Great 10k Run for the British Heart Foundation on the 15th of May. I’ve decided to choose the BHF as i know several people who have been affected by Heart problems and if i can help the BHF with a contribution towards helping them continue the great work that they do, then the pain of the run will be satisfying!

People are at the heart of what the BHF does, but this isn’t possible without the support and charitable donations of you guys So…………

Please, Please, Please donate generously so that together we can beat heart disease.

Vodpod videos no longer available.

Text File Comparison Tool – Winmerge

WinMerge is an Open Source differencing and merging tool for Windows. WinMerge can compare both folders and files, presenting differences in a visual text format that is easy to understand and handle.

http://winmerge.org/

ULTRAEDIT application – Very Useful for editing text files

Probably one of the best apps out there for editing text files, and being able to do automated actions against files. Versatile and easy to use, UltraEdit is the ideal text, hex, XML, HTML, PHP, Java, Javascript, Perl, and programmer’s editor.

http://www.ultraedit.com/

UltraEdit Support

http://www.ultraedit.com/forums/viewforum.php?f=54

Download User Guide

http://www.ultraedit.com/files/uemanual.zip