Friday, 18 March 2011

Recover data from a failing drive (possibly with bad sectors)

ddrescue is a fabulous tool/utility available in Linux. It can help to recover data from any failing hard disk. If your drive has failed, i.e. your drive cannot be detected by the BIOS, ddrescue will be of no help and the drive would need to be sent to a data recovery expert (who will charge you hundreds of dollars to recover what ever data possible).

ddrescue is available on SystemRescueCD. SystemRescueCD is exactly what it says it is - a system rescue CD, which uses Linux, and boots up either from a CD or a USB stick. It is possibly the one most important piece of software which I would advice any PC user to have. Or course, you would need to be familiar with the Linux OS and you would need to have some basic knowledge of the Linux interface. This article will not dive into the details of the SystemRescueCD. So, let's get back to ddrescue.


NOTE: In the steps below, "/dev/sdc" is the drive which has the failing drive. "/dev/sdb" is the good/new drive, which is the destination to copy the data to. "/mnt/usbstick/ddrescuelog.log" is the logfile which will be created (if you do not have this log file, re-trying failures or resuming recovery if the system needs to be shutdown will not be possible). Replace the above with the appropriate paths as needed for your own purposes.

Steps to recover as much data possible from a drive which has bad sectors:
1. Copy as much data as possible, without retrying or splitting sectors:
ddrescue --no-split /dev/sdc /dev/sdb /mnt/usbstick/ddrescuelog.log

2. Now let it retry previously detected errors 3 times:
ddrescue -r 3 /dev/sdc /dev/sdb /mnt/usbstick/ddrescuelog.log

3. Run successive passes like this to use the log file to only read the gaps with errors:
ddrescue -r 3 --complete-only /dev/sdc /dev/sdb /mnt/usbstick/ddrescuelog.log

4. Now let it retry previous errors 3 times, using uncached reads:
ddrescue --direct -r 3 /dev/sdc /dev/sdb /mnt/usbstick/ddrescuelog.log

5. If that fails, try again but retrimmed, so it tries to reread full sectors:
ddrescue --direct --retrim -r 3 /dev/sdc /dev/sdb /mnt/usbstick/ddrescuelog.log

These steps should be somewhat sufficient to retrieve as much data as possible from a failing drive. There is not guarantee that all the data will be able to be retrieved. Only data from sectors which do not have any physical damage will be able to be retrieved.

It helped me.

For other links on this matter, you can also refer to the following links:

What I have not tried, which these websites suggest are the following:
- ntfsfix /dev/sdc
- fsck -t ntfs
- fsck.ntfs

Friday, 18 February 2011

Determine which application is using a particular port

Say you try to install an application which needs to use port 80. But during or after the installation, the application is not able to launch because port 80 is already in use, how do you determine which application is holding on to port 80?

In Windows, it is simple and fairly straight forward.

Follow the steps below:
1. Issue the following command to check which process is using port 80:
netstat -aon | findstr 0.0:80

NOTE: If you wanted to check for any other port number, replace the "80" in the command above with the port number of choice.2. The output could look like this:
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 2920

For the example above, referring to the number highlighted in yellow, this is the process id which is using/listening to port 80. The process id is assigned by the OS to an application/service which is running (it could be running in the background)

3. Issue the following command to get the name of the process which as the process id (as shown in the yellow text above - this value can be any number as assigned by the system, i.e. never fixed)
tasklist | findstr 2920

4. This command would yield an output which would have the following format:
httpd.exe 2920 Console 0 12,724 K

Based on the example above, the application using process id 2920 is "httpd.exe".

So, from here, you can see that port 80 is being used by process id 2920, where process id 2920 was assigned by the OS to httpd.exe which is running in the background (NOTE: this is on my system - If I was to restart my PC or stop httpd.exe and restart it, the process id would highly likely not be the same)

Sunday, 9 January 2011

Monday, 1 November 2010

Enabling/disabling IE's proxy via the registry

The registry entry which needs to be modified when you want to enable or disable the proxy for IE is
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings

Byte 9 has to be modified such that if you wanted to enable it, bit 2 has to be set. Alternatively, if you wanted the proxy to be disabled, bit 2 has to be cleared.

Example 1
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections]
"DefaultConnectionSettings"=hex:46,00,00,00,a8,1e,00,00,03,00,00,00,6e,....

In the example above, bit 2 of byte 9 is set. This means that the proxy is enabled.

Example 2
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections]
"DefaultConnectionSettings"=hex:46,00,00,00,a8,1e,00,00,01,00,00,00,6e,....

In the example above, bit 2 of byte 9 is cleared. This means that the proxy is disabled.

Tuesday, 12 October 2010

Issue with "Start without debugging" in Visual Studio 2010

With Visual Studio 2010 (VC++), after compiling and linking a project, attempting to run the application using "Start without debugging" will result in the console window opening and closing automatically.

To overcome this problem, the following needs to be done:
Project -> Properties -> Configuration Properties -> Linker -> System, please select Console (/SUBSYSTEM:CONSOLE) in SubSystem dropdown

Wednesday, 6 October 2010

Merging and splitting PDF files

If you want to merge multiple PDF files or split a PDF file, an excellent free tool avalable is PDF Split and Merge. It can do more that just split and merge PDF files.

It can be downloaded from the following URL:
http://www.pdfsam.org/

It has a simple and intuitive interface, with which you can:
  • split your pdf documents (into chapters, single pages, etc.)
  • merge many pdf documents or subsections of them
  • extract sections of your document into a single pdf document
  • mix alternate pages taken from two pdf documents in straight or reverse order into a single document
  • rotate pages of the selected pdf documents
  • visually reorder pages of a selected pdf document
  • visually compose a document dragging pages from selected pdf documents
  • save and load your environment to automatize your recurrent jobs
  • manage pdfsam settings and set an environment to load at start up

There is also an enhanced version of this tool, which has all the basic features plus:
  • encrypt your pdf files (RC40 bits, RC128 bits, AES128 bits) and set permissions on them
  • add a pdf frontpage or an addendum (or both) to your pdf documents
  • decrypt pdf documents
  • extract attachments from your pdf documents
  • set viewer options to a document to tell the viewer application how should open the document
  • set the metadata of a document (author, title, subject and keywords)

The features available and a comparison between the basic and enhanced version cna be found in the following link:
http://www.pdfsam.org/?page_id=42

Monday, 27 September 2010

Getting the size of a MySQL database

This is the command to get the size of the MySql database

SELECT table_schema "Data Base Name",
  sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
  sum( data_free )/ 1024 / 1024 "Free Space in MB"
  FROM information_schema.TABLES
  GROUP BY table_schema;