合 如果$GRID_HOME或$GRID_BASE或/u01目录下的所有文件权限被人为误操作修改了,那么如何来修复该权限问题?
Tags: Oracle故障处理误操作恢复权限问题$GRID_HOME权限被修改$GRID_BASE/u01
权限被修改
如果使用chown -R误操作将整个$GRID_HOME或$GRID_BASE或/u01目录下的所有文件权限修改了,或者删除了Oracle 11g rac中$GRID_HOME/log文件夹下的所有内容,那么将导致集群不能正常启动。
误操作的命令如下所示:
1 2 | chown -R oracle.oinstall /u01 chmod -R 444 /u01 |
可以通过命令“cluvfy comp software -n all -verbose
”来校验集群的权限是否正确。
修复方法
大致可以通过如下几种方法来修复权限问题:
方法1:rootcrs.pl -init
根据MOS文档1931142.1提供的建议,可以通过root用户执行命令$GRID_HOME/crs/install/rootcrs.pl -init(11gR2 PSU>11.2.0.3.6的集群)或roothas.pl -init(11gR2 PSU>11.2.0.3.6的单实例)进行解决。对于Oracle 12c版本,需要将rootcrs.pl或roothas.pl修改为rootcrs.sh和roothas.sh。该方法可以用来解决删除了Oracle 11g rac中$GRID_HOME/log文件夹下的所有内容,导致集群不能启动的情况,但是,对于chown -R误操作将整个$GRID_HOME或$GRID_BASE或/u01目录的权限修改了的情况不一定能恢复。
需要注意的是,rootcrs.pl –init是在PSU>11.2.0.3.6下执行的,如果PSU<11.2.0.3.6,那么可以执行如下两条命令来实现同样的效果。
1 2 | <GRID_HOME>/crs/install/rootcrs.pl -unlock <GRID_HOME>/crs/install/rootcrs.pl -patch |
方法2:脚本permission.pl
采用MOS文档1515018.1上提供的脚本permission.pl在权限正常的节点上生成修复脚本,然后将生成的修复脚本在异常节点上执行来修复权限问题。可以用来修复chown -R误操作将整个$GRID_HOME或$GRID_BASE或/u01目录的权限修改了的情况。
permission.pl脚本的内容如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #!/usr/bin/perl -w # # Captures file permissions and the owner of the files # useage : perm1.pl <path to capture permission> # # MODIFIED # uaswatha 12th March 2018 address filename with spaces (request from customer) use strict; use warnings; use File::Find; use POSIX(); my (@dir) = @ARGV; my $linecount=0 ; #print @ARGV, $#ARGV; if ($#ARGV < 0) { print "\n\nOpps....Invalid Syntax !!!!\n" ; print "Usage : ./perm1.pl <path to capture permission>\n\n" ; print "Example : ./perm1.pl /home/oralce\n\n" ; exit ; } my $logdir=$dir[0] ; #my ($sec, $min, $hr, $day, $mon, $year) = localtime; ##my ($dow,$mon,$date,$hr,$min,$sec,$year) = POSIX::strftime( '%a %b %d %H %M %S %Y', localtime); my $date = POSIX::strftime( '%a-%b-%d-%H-%M-%S-%Y', localtime); my $logfile="permission-".$date; my $cmdfile="restore-perm-".$date.".cmd" ; open LOGFILE, "> $logfile" or die $! ; open CMDFILE, "> $cmdfile" or die $! ; find(\&process_file,@dir); print "Following log files are generated\n" ; print "logfile : ".$logfile. "\n" ; print "Command file : ".$cmdfile. "\n" ; print "Linecount : ".$linecount."\n" ; close (LOGFILE) ; close (CMDFILE) ; sub process_file { my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks,$username,$user,$pass,$comment,$home,$shell,$group); my %uiduname = () ; my %gidgname = () ; my $filename = $File::Find::name; #### Building uid, username hash open (PASSWDFILE, '/etc/passwd') ; while ( <PASSWDFILE>) { ($user,$pass,$uid,$gid,$comment,$home,$shell)=split (/:/) ; $uiduname{$uid}=$user ; } close (PASSWDFILE) ; #### Building gid, groupname hash open (GRPFILE, '/etc/group') ; while ( <GRPFILE>) { ($group,$pass,$gid)=split (/:/) ; $gidgname{$gid}=$group ; } close (GRPFILE) ; ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat("$filename"); # printf "%o %s %s %s\n", $mode & 07777, $uiduname{$uid}, $gidgname{$gid}, $filename ; printf LOGFILE "%o %s %s %s\n", $mode & 07777, $uiduname{$uid}, $gidgname{$gid}, "\"$filename\"" ; printf CMDFILE "%s %s%s%s %s\n", "chown ",$uiduname{$uid}, ":", $gidgname{$gid}, "\"$filename\"" ; printf CMDFILE "%s %o %s\n", "chmod ",$mode & 07777, "\"$filename\"" ; # printf "%o %s %s %s\n", $mode & 07777, $uiduname{$uid}, $gidgname{$gid}, \",$filename,\" ; $linecount++ ; } |
需要注意的是,该脚本会产生2个文件:
1 2 | a. permission-<time stamp> - This contains file permission in octal value, owner and group information of the files captured b. restore-perm-<time stamp>.cmd - This contains command to change the permission, owner, and group of the captured files |
修复时只需要执行restore-perm-
1 | :%s/raclhr-11gr2-n2/raclhr-11gr2-n1/g # 替换每一行中所有 raclhr-11gr2-n2 为 raclhr-11gr2-n1 |
修复目录/u01/app的过程如下所示: