Saturday 31 March 2012

Remove unused filesystem from linux

On one of the redhat server, found a non-standard filesystem was mounted under /migwork.
From the name, it looks like it was used for some migration work.

check whether the file system is still in use
$ fuser /migwork

No process is using /mitwork, so we can safely remove it.
$ umount /migwork

update /etc/fstab to prevent it from being mounted after reboot.
#/dev/md20        /migwork        ext3        defaults     1 2

check the information about md20
$ cat /proc/mdstat
$ mdadm --detail /dev/md20 | sed -n '/RaidDevice/,$p'

destroy md20
$ mdadm --stop /dev/md20
$ mdadm --remove /dev/md20

mdstat showed these sub disks are from SAN, inform storage engineer to take them back.

Saturday 24 March 2012

How to disable fsck on reboot

In Linux, when a filesystem is mounted for certain times, or its last fsck was more than certain days ago, system will perform fsck on it when server reboot. The fsck process can take a few minutes to hours to finish, depending on the filesystem size.

If we want fast reboot, we can disable the fsck check, although it's not recommended to do so.
To disable fsck, there are a few ways.

1. update /etc/fstab
in /etc/fstab, the last column is used by fsck to determine the order of performing file system check at reboot time. For root file system /, it should be 1, for other file systems, it should be 2. If we want to disable the fsck check for certain file system, we can specify 0 in the last column.
$ grep nofsck /etc/fstab
/dev/sda2        /mnt/nofsck        ext4        defaults        0  0

2. use tune2fs to change the filesystem parameters
To list the current settings:
$ tune2fs /dev/sda2 | egrep -i 'mount count|check'
Mount count:                        1
Maximum mount count:        21
Last checked:                     Sat Mar 24 16:15:33 2012
Check interval:                    15552000 (6 months)
Next check after:                 Thu Sep 20 16:15:33 2012

the output is self-explained, for my system, /dev/sda2 will be checked after it's mounted for 21 times, or after Sep 20 16:15:33 2012.

To disable fsck check on /dev/sda2
$ tune2fs -c 0 -i 0 /dev/sda2
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds.
check it again:
$ tune2fs /dev/sda2 | egrep -i 'mount count|check'
Mount count:                        1
Maximum mount count:        -1
Last checked:                     Sat Mar 24 16:15:33 2012
Check interval:                    0 (<none>)


3. Tell system to skip fsck when rebooting.
$ /sbin/shutdown -rf now

the -f flags tells system to skip fsck for all filesystems during the reboot. Unlike the fstab and tune2fs methods, it only takes effect during current reboot, will not disable fsck permanently.

Thursday 22 March 2012

Rename multiple files using one command

On Redhat Linux machine, suppose we have hundreds of .txt files, if want want to rename them to .sh file, there are a few ways to do:

1. use rename command
rename txt sh *.txt

2. write script
for f in *.txt; do mv $f ${f/.txt/.sh}; done

${f/.txt/.sh} is string replacement in bash, for details, please see string manipulation in bash

Wednesday 21 March 2012

NetBackup: how to restore oracle backup to a different server

Production environment is running on RAC, prod1 and prod2 are the cluster members.
We need to restore the production data to a testing server test1 for application testing, if test1 uses the same NetBackup master and media servers, we can restore the data using this rman code
set dbid = 1234567890;
connect target /
connect catalog rmanid/rmanpass@rmancatalog

RUN {
allocate channel c1 type 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=prod1)' maxopenfiles 10;
allocate channel c2 type 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=prod2)' maxopenfiles 10;
set until time "TO_DATE('2012-03-21 12:30:00', 'YYYY-MM-DD HH24:MI:SS')";
restore controlfile;
sql 'alter database mount';
restore database;
recover database;
release channel c1;
release channel c2;
 }

But if we try the restore directly, we will get this error:
ERROR: client is not validated to perform the requested operation.

Before restoration, we have to allow test1 to restore from the backup made on prod1 and prod2. To do this, you need log on to the backup master server. In directory /usr/openv/netbackup/db/altnames, create a file named test1, in file test1, put prod1 and prod2 as the content.

$ cat /usr/openv/netbackup/db/altnames/test1
prod1
prod2
$