当前位置:网站首页>Oracle11g database uses expdp to back up data every week and upload it to the backup server

Oracle11g database uses expdp to back up data every week and upload it to the backup server

2022-06-28 15:05:00 1024 Q

Catalog

1. Look at the database

1.1 First, let's take a look at the table space , The production environment table space is about 90G, Less than half of it was used

2. Database backup

2.1 Login database

2.2 Create a logical Directory

2.3 Give database user file operation permission #dbuser User name for database , More practical changes

2.3 Create a physical Directory

1.3 Backup database

3.shell Script for automatic backup

4. Add timing task

4. Reference article

The school needs to back up the previous production database to Huawei cloud , After that, automatic weekly backup will be realized

1. Look at the database 1.1 First, let's take a look at the table space , The production environment table space is about 90G, Less than half of it was used

View all tablespaces and usage

SELECT  B.FILE_NAME Physical file name ,  B.TABLESPACE_NAME Tablespace name ,  B.BYTES/1024/1024 size M,  (B.BYTES-SUM(NVL(A.BYTES,0)))/1024/1024 Already used M,  SUBSTR((B.BYTES-SUM(NVL(A.BYTES,0)))/(B.BYTES)*100,1,5) Usage rate FROM DBA_FREE_SPACE A,DBA_DATA_FILES BWHERE A.FILE_ID=B.FILE_IDGROUP BY B.TABLESPACE_NAME,B.FILE_NAME,B.BYTESORDER BY B.TABLESPACE_NAME;

2. Database backup 2.1 Login database [[email protected]]$ sqlplus / as sysdba2.2 Create a logical Directory

This operation will not be performed in Linux Created in /opt/data_backup This file , Finally, you need to create the file manually to back it up .

SQL> create directory back_dir as '/opt/backup'SQL> select * from dba_directories; # View all logical directories , See if the creation is successful 2.3 Give database user file operation permission #dbuser User name for database , More practical changes Grant read,write on directory back_dir to dbuser;2.3 Create a physical Directory [[email protected]]$ mkdir -p /opt/backup #-p Ensure that the directory name exists , It does not exist to build a , You can use parameters to create multi-level directories 1.3 Backup database [[email protected]]$ expdp dbuser/[email protected]:1521/orcl dumpfile=dbback.dmp log=log.log directory=back_dir schemas=cbyxy

exedp There are a lot of parameters , Here are some explanations used
dbuser/[email protected]:1521/orcl # Export user name / password @ database IP/ database SID
dumpfile= Exported file name .dmp
log= Log name of the export process .log
directory= The path name of the backup file , Use the previous logical directory name
schemas= The name of the database user to be backed up
FULL=y # This means that you do not need to export the entire database schemas Parameters
You can also export by tablespace TABLESPACES=
Table name export TABLES=
And so on. There are many parameters you can learn by yourself

3.shell Script for automatic backup #!/bin/bash# Import environment variables , Fill in according to your actual situation export ORACLE_BASE=/home/oracle/appexport ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1export PATH=$ORACLE_HOME/bin:$PATHexport LOCAL_IP=192.168.110.183:1521export [email protected]:/opt/ # Backup server users ,ip, Save address export ORACLE_USER_NAME=system # The user password of the database shall be filled in according to the actual situation , Backing up the entire library is best done with system or sys Administrator user export ORACLE_USER_PASSWD=Abc123556..export ORACLE_SID=orcl # I don't know if I can use Oracle User execution echo $ORACLE_SID, perhaps SQL> SELECT instance_name FROM v$instanceexport DATA_DIR=/opt/backup # Same as the logical address in the database , Used to store backup files export DELTIME=`date -d "7 days ago" +%Y%m%d` # -d "7 days ago" To get the date seven days ago , Name the task by date to facilitate automatic deletion of tasks > except export BAKUPTIME=`date +%Y%m%d` # Backup date: export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK # Environment variables that define language locale and character set attributes , Modify according to your own database mkdir -p $DATA_DIRecho "Starting bakup..."echo "Backup file path $DATA_DIR/$BAKUPTIME.dmp"expdp $ORACLE_USER_NAME/[email protected]$LOCAL_IP/$ORACLE_SID dumpfile=$BAKUPTIME.dmp log=$BAKUPTIME.log directory=expdp full=yecho "backup file success..."tar -zcvPf $DATA_DIR/$BAKUPTIME.tar.gz $DATA_DIR/$BAKUPTIME.dmp --remove-files ##-P: Specify the absolute path --remove-files : Delete the original file after packaging echo "tar the file backup successfully"echo "scp to":$BACKUP_IPscp $DATA_DIR/$BAKUPTIME.tar.gz $BACKUP_USER_IP_DIR # The remote server firewall has restrictions scp Port needs to be added :-P Port number rm -f $DATA_DIR/$DELTIME.log # Delete previous backup echo "Bakup completed."

4. Add timing task [[email protected] ]$ crontab -e

add rows :* 1 * * 6 /opt/back.sh # Perform the backup task every Saturday morning

* * * * *- - - - -| | | | || | | | +----- What day of the week (0 - 6) ( Sunday by 0)| | | +---------- month (1 - 12) | | +--------------- Day of the month (1 - 31)| +-------------------- Hours (0 - 23)+------------------------- minute (0 - 59)4. Reference article

https://www.cnblogs.com/xwdreamer/p/3511047.html
https://www.cnblogs.com/farmer-y/p/5888432.html
https://blog.csdn.net/weixin_41607523/article/details/110817646
https://blog.csdn.net/XUEYUTIANQI/article/details/113976558

This is about Oracle 11g Database usage expdp This is the end of the article on weekly data backup and uploading to the backup server , More about Oracle 11g Use expdp Please search the previous articles of SDN or continue to browse the related articles below. I hope you can support SDN more in the future !


原网站

版权声明
本文为[1024 Q]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/179/202206281501034285.html