Data is the core of the application, the program is broken the re-release of the machine can be, but once the loss of data, the loss will be irreversible, the program released to production, data backup is particularly important, because not all services have funds to complete advanced backup such as RAC and DG, In our only one database server, temporarily take the simplest backup strategy, export the DMP to save.
One, backup script
1. Initialize variables, record start log
#变量sysname=fill in your system name Syspath=/home/oracle/databak/$sysnamev _date=$(Date '+%y%m%d%h%m%s') #日志目录logfile=${syspath}/backup.${v_date}.log# Print Start timeEchoBackup_time>>${logfile}Date '+%y-%m-%d%h:%m:%s'>>${logfile}Echo "Backup JCD">>${logfile}Echo "start_time">>${logfile}Date '+%y-%m-%d%h:%m:%s'>>${logfile}
2. Enter Oracle directory to set parameters for Oracle
/home/11g/app/oracle/product/11.2. 0 export oracle_home=/home/11g/app/oracle/product/11.2. 0/db_1export PATH= $PATH:/home/11g/app/oracle/product/11.2. 0/db_1/binexport oracle_sid=sid Name
3. Export Data
Echo $SYSPATHV _date=$ (date'+%y%m%d%h%m%s') filename= $syspath/ jcd${v_date}.dmp# Export command exp username file=${filename} compress=n >> ${logfile}echo"end_time ">>${logfile}date'+%y-%m-%d%h:%m:%s' >>${logfile}
4, Compressed Dump package
gzip ${filename}
5. Use SCP to pass the compressed package to the backup server, note that the directory on the backup server needs to be pre-created
SCP ${filename}.gz [email protected]remot_ip:/home/weblogic/databak/backup directory
Second, set the script execution time
We set the rules to be executed 2 o'clock in the morning every day, using crontab for processing.
Execute CRONTAB-E, set the following rules
0 2 sh /home/oracle/db. SH
Third, about the SCP command password processing
When you execute the SCP command, you are prompted to enter the password for the remote host
SCP ${filename}.gz [Email protected]_ip:/home/weblogic/databak/backup directory
There are two ways to resolve this:
1. Using encrypted files for authentication
1) Enter the ~/.SSH directory of the Local host
2) Run Ssh-keygen-t [RSA|DSA], will generate key file and private key file Id_rsa,id_rsa.pub or id_dsa,id_dsa.pub, here we use RSA mode
3) Modify the generated Id_rsa and Id_rsa.pub permissions to 700
4) Copy the. pub file to the remote host's ~/.ssh directory, execute the cat id_rsa.pub >> ~/.ssh/authorized_keys, and transfer the contents into the Authorized_keys file
5) Modify the authorized permission to 700
After completing the above modification, from the local host SCP to the remote host without a password, a simple understanding should be the communication, the local host to send the SCP command, the local private key to sign, the remote host using public key verification, judge asked the host can trust, open communication services.
2. Use the expect command to complete the password interaction
The expect command is primarily used in scripts where there must be manual intervention, pre-input instructions, simulated scenes to use the expect command to capture the text that prompts for input instructions, and once the text appears, automatically use the Send command to enter commands that require interaction.
Use here for:
" *password: " "your password\r"#此处填写我们输入的交互命令 expect EOF
[Automatic operation and maintenance]oracle automatic backup