Script to capture and restore file permission in a directory (for eg. ORACLE_HOME) (Doc ID 1515018.1)
APPLIES TO
Gen 1 Exadata Cloud at Customer (Oracle Exadata Database Cloud Machine) - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Backup Service - Version N/A and later
Oracle Database Cloud Exadata Service - Version N/A and later
Oracle Database Cloud Service - Version N/A and later
Generic UNIX
Generic Linux
MAIN CONTENT
PURPOSE
This script is intended to capture and restore the file permission of a given directory example - ORACLE_HOME. The script will create a output file called permission_
REQUIREMENTS
The script needs to be run on command prompt of Unix platform .
Perl is required to execute this script
Shell is required to run the shell script .
CONFIGURING
Download and save the script on your server as permission.pl
Provide the execute permission on the script
INSTRUCTIONS
Run the script from the location where you have downloaded and saved it
1 | ./permission.pl <Path name to capture permission> |
CAUTION
This sample code is provided for educational purposes only and not supported by Oracle Support Services. It has been tested internally, however, and works as documented. We do not guarantee that it will work for you, so be sure to test it in your environment before relying on it.
Proofread this sample code before using it! Due to the differences in the way text editors, e-mail packages and operating systems handle text formatting (spaces, tabs and carriage returns), this sample code may not be in an executable state when you first receive it. Check over the sample code to ensure that errors of this type are corrected.
Note : This script can restore permission back to the point at which it was captured. It is not intended to reset the permission.
SCRIPT
Execute the script from the dollar ($) prompt
Steps to capture permission of a directory
- Download the script from here
- Log in as “oracle” user
- copy the file to a location say /home/oracle/scripts
- Give execute permission
1 | $ chmod 755 permission.pl |
- Execute the script to capture permission
1 | $ cd /home/oracle/scripts |
Script generates two files
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
Steps to restore captured permission of the directory
Copy the “restore-perm-
Give execute permission to file generated during capture
1 | chmod 755 restore-perm-<timestamp>.cmd |
- execute .cmd file to restore the permission and the ownership
1 | $ ./restore-perm-<timestamp>.cmd |
Note: In case of RAC setup for GRID_HOME, execute permission.pl and restore-perm-
Note: In case of RAC setup review the file restore-perm-
Sample output of the script
permission-<time stamp>
1 | 755 oracle oinstall <ORACLE_HOME> |
restore-perm-<time stamp>.cmd
1 | chown oracle:oinstall <ORACLE_HOME> |
最后,也可以参考 陈举超 超哥的讲解文章:Oracle RAC目录权限丢失故障恢复