CPIO Tape with Unknown Block Size

February 7, 2010

Here are same useful CPIO command samples (assume the tape is /dev/st0):

  1. To list out the content of the tape:
    cpio -tv -F /dev/st0
  2. To extract the tape to working directory:
    cpio -iv -F /dev/st0
  3. To archive files from working directory to tape:
    find . -print | cpio -ov -F /dev/st0

Sometime we might face problem in extracting the tape because wrong block size is used. To check the block size used in a CPIO archived tape catridges, try command below:

dd if=/dev/sto of=/tmp/deleteme ibs=64k count=1

If no error prompts out, it means the tape is archived in 64k. Else try other block size number such as 128k until you find a figure that doesn’t result an error message. The command will create a dummy file called deleteme at /tmp, which can safely be removed. After you know the block size, use command below to list or extract the content of the tape:

cpio -tv --block-size 64 -F /dev/st0

cpio -iv --block-size 64 -F /dev/st0


Wireshark the Packet Sniffer in Linux

January 28, 2010

Wireshark is a packet sniffer program that run on Linux machine (formerly known as Ethereal), and of course available to Windows as well. Basically it will record down what ever going through a specified port. To use it, you need to install the following packages:

  1. wireshark package: tools that do the sniffing.
  2. wireshark-gnome package: used to read the PCAP files created by wireshark (not sure whether can run in KDE or got KDE version or not).
  3. libsmi package: library required to install wireshark.

After everything is installed, you can execute wireshark using tshark command:

tshark

It will output a live packet sniffing to the terminal, however it is not much usage for this case. The following command is to run tshark in daemon mode and save the PCAP files in a specified location:

tshark -q -i eth0 -b files:80 -b filesize:10000 -w /root/trace/trace -x -t ad port 80

q: quiet mode or daemon mode

i: network interface

b: ring buffer option, which means it can set to save the data in multiple files in a mary go round pattern. files means how many files to save, filesize means maximum size of 1 single file (in KB)

w: file path where the PCAP file saved, aware that file number will be append to the file name when it is saved to multiple files.

x: tell wireshark to save the hex and ACSII dump

t: time format, ad means absolute date and time

port: which port to be sniffed

While to read the PCAP file, you need to be in Gnome Desktop and execute wireshark command:

wireshark

A wireshark GUI program will appear, and all you need to do is open the PCAP file that you want to read.

This is the wireshark Startup Script (change the filename from wireshark.doc to wireshark), copy it to /etc/init.d and issue chkconfig --add wireshark to add it into services.


Install Tomcat Startup Script in Linux

January 21, 2010

Make Tomcat auto startup in Windows is easy, either install it as service or just put the startup batch into Windows startup list. But not for Linux. After you install (or unzip) Tomcat into your Linux machine, and everything tested OK, you can use steps below to make Tomcat startup as service in Linux (referring to Startup script for Tomcat on Centos | Redhat | Fedora):

  1. Download the startup script from here. There are 2 files inside the zip file: tomcatd and tomcatRunner.
  2. Extract them to /etc/init.d. Make sure they are runnable.
  3. Edit parameters below inside tomcatd file:
    1. JAVA: location of your java utility, for example /usr/java/jdk1.6.0_17/bin/java.
    2. tomcatuser: user that will run the service, usually I just change it to root. (default is tomcat)
    3. CATALINA_HOME: location of your Tomcat, example /usr/tomcat.
  4. Make a tomcat directory in /var/run:
    mkdir /var/run/tomcat
  5. Add the tomcat service:
    chkconfig --add tomcatd
  6. Now you should able to test out the service:
    service tomcatd restart

Change MySQL Database Location in Linux

January 14, 2010

Install MySQL in Linux doesn’t like in Windows, either install during OS installation or install separately, you can’t define the location you want the database to be located. Steps below is to change the location of the database (or reallocate):

  1. Stop MySQL service (the service name may be different)
    service mysql stop
  2. Copy MySQL data file to destination (usually the default database directory is /var/lib/mysql. Make sure the owner of the directory and files are mysql.
    cp -r /var/lib/mysql /destination
  3. Go inside the database directory and remove the log files (usually have 2).
    rm /destination/ib_log*
  4. Locate MySQL configuration file. You can find it at /etc/my.cnf. If no such file exists, copy a sample of configuration file from /usr/share/mysql/. There will be a few files to be selected (named as my-xxx.cnf). Copy any of them to /etc and rename to my.cnf.
  5. Edit MySQL configuration file. Go to section mysqld and look for the keyword datadir (add in if not exist). Change the location to the destination.
    datadir=/destination/
  6. Start MySQL service and done.
    service mysql start

Migrate Data using Transportable Tablespace in Oracle

January 7, 2010

There are few types of data migration methods: offline migration, migrate using exp and imp utilities, migrate using expdp and impdp utilities and of course using transportable tablespace. You can refer Oracle Database Cross Platform Transportable Tablespace for more details.

To perform migration using transportable tablespace:

  1. At source database, make the tablespace readonly
    alter tablespace users read only;
  2. Export it as SYSDBA
    exp file=exp.dmp log=exp.log tablespaces=users transportable_tablespaces=y
  3. Copy over the dump file and the tablespace data files to the destination
  4. At source database, put the tablespace back to read write mode
    alter tablespace users read write;
  5. If the same tablespace exists in the destination database, make  it offline and drop it.
    drop tablespace users including contents and datafiles;
  6. Lastly import the copied dump file:
    imp file=exp.dmp log=exp.log tablespaces=users transportable_tablespace=y datafiles=('/u01/users01.dbf', '/u01/users02.dbf')

Reduce Size of TEMP Tablespace

December 28, 2009

Similar to Reduce Size of UNDO Tablespace, you need to recreate temporary tablespace in order to reduce the size. Issue a resize statement might result error below:

alter database tempfile '/u01/database/temp1.dbf' resize 250M
ORA-03297: file contains used data beyond requested RESIZE value

To recreate the temporary tablespace, you need to create a second temporary tablespace:

  1. Create second temporary tablespace
    create temporary tablespace temp2 TEMPFILE '/u01/database/temp2.dbf'size 5M reuse autoextend on next 1M maxsize unlimited extent management local uniform size 1M;
  2. Set second temporary tablespace as default
    alter database default temporary tablespace temp2;
  3. Drop the first temporary tablepsace
    drop tablespace temp including contents and datafiles;
  4. Recreate first temporary tablespace
    create temporary tablespace temp tempfile '/u01/database/TEMP01.dbf' size 300M reuse autoextend on next 50M maxsize unlimited extent management local uniform size 1M;
  5. Set first temporary tablespace as default
    alter database default temporary tablespace temp;
  6. Drop the second tablespace
    drop tablespace temp2 including contents and datafiles;

Reduce Size of UNDO Tablespace

December 21, 2009

UNDO tablespace can grow quickly if long and uncommitted transactions are executed, sometime even take out the whole hard disk and crash the database, and lastly database itself not even can be started up.

To reduce the size of the data file (especially when it has taken all your hard disk space), we need to recreate the default UNDO tablespace because the resize data file statement will not work:
alter database datafile 'undo.bdf' resize 100M;

  1. Log in as sysdba
    connect / as sysdba
  2. Start database in nomount state
    startup nomount;
  3. Create temporary UNDO tablespace in anywhere got free space
    create undo tablespace undo2 datafile '/tmp/undo2.dbf' size 50M autoextend off;
  4. Set the temporary UNDO tablespace as default UNDO tablespace
    alter system set undo_tablespace = undo2;
  5. Drop the original UNDO tablespace.
    drop tablespace undo1 including contents and datafiles;
  6. Recreate the original UNDO tablespace.
    create undo tablespace undo1 datafile '/u01/database/undo1.dbf' size 500M autoextend on next 5M maxsize 1000M;
  7. Set back the original UNDO tablespace to default UNDO tablespace
    alter system set undo_tablespace = undo1;
  8. Drop the temporary UNDO tablespace
    drop tablespace undo2 including contents and datafiles;

CHKCONFIG Equivalence in Ubuntu

December 14, 2009

CHKCONFIG is a utility for the Red Hat family of Linux, to configure the background services. While in Ubuntu, you can either install CHKCONFIG:

sudo apt-get install chkconfig

Or use the Ubuntu service configuring utility RCCONF:

sudo rcconf

It has a nice console interface for user to enable or disable the services.


SQL Server Cannot Start After Unused For a Long Time

December 7, 2009

If you’re using SQL Server in Windows XP, you might have problem to start the database service after a long period of unused. You can see error message below log in the error log (check the log directory where you install SQL Server):

The file "C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\master.mdf" is compressed but does not reside in a read-only database or filegroup. The file must be decompressed.

This is resulted by a compression feature of Windows XP, which certain files will be compressed after unused for a period of time. To reconfirm the situation, change directory to data directory and right click on any of the MDF or LDF file. Click Properties, at the bottom of General Tab click the Advance button. You can see the Compress contents to save disk space at the Compress or Encrypt attributes section is ticked.

To solve the problem, untick this feature of all the MDF and LDF files in the Data directory, and your database service should be able to start.


Tape Drive Hardware Compression

December 1, 2009

Tape drive normally come with hardware compression feature. For example an LTO3 tape can store 400GB data with the hardware compression feature disabled, and able to store 800GB data with hardware compression feature enabled. Hardware compression is done at the tape drive, instead of using TAR or ZIP command.

By default, the hardware compression is enabled. To disable it, you can issue command below:

mt -f /dev/st0 compress 0

To enable back the compression feature:

mt -f /dev/st0 compress 1

To disable the default option of hardware compression:

mt -f /dev/st0 defcompression -1

To enable back the default option:

mt -f /dev/st0 defcompression 1

Transfer rate is much higher with hardware compression enabled.