Search code examples
database-administrationoracle19c

How to write a script of getting backup of remote Oracle database


I have an Oracle database 19c with IP, x.x.x.a that have a lot of important tables. I want to get backup of that and save it on another system with IP,x.x.x.b. I did this actions on the x.x.x.b system:

  • Install an Oracle database 19c which won't be used to have data in his own.

  • Install Oracle database client 19c and set ORACLE_HOME in ~/.bashrc

  • Set JAVA_HOME

  • Finally, use this script to get backup of the Oracle Database on x.x.x.a:

    #!/bin/bash
    export ORACLE_HOME=/home/oracle/oracle_database_client
    export PATH=$ORACLE_HOME/bin:$PATH
    rman target sys/******@//x.x.x.a:1521/ORCL
    
    BACKUP INCREMENTAL LEVEL 0 DATABASE PLUS ARCHIVELOG FORMAT '/home/oracle/backup_oracle_process/backup_files/%U';
    exit;
    

I prefer to get backup using script in the clear way and use the script in crontab to run every week. I gave +x permission to the script,backup_script.sh, and run it. But unfortunately, it stop on RMAN> prompt and when exited from that this error message was shown:

BACKUP command not found.

Moreover, I read all questions about this subject like this:

https://stackoverflow.com/a/72397334/6640504

But none of them does what I want.

Would you please guide me how to solve the problem and have a script to get backup of Oracle database?

Any help is really appreciated.


Solution

  • You are just starting RMAN and not passing it any commands. Then when you exit RMAN you are trying to run the RMAN commands from the command prompt (rather than in RMAN).

    Put your RMAN backup command(s) into a file:

    BACKUP INCREMENTAL LEVEL 0 DATABASE PLUS ARCHIVELOG FORMAT '/home/oracle/backup_oracle_process/backup_files/%U';
    

    Then your script should use @filename to pass the name of a command file to execute (see the documentation):

    #!/bin/bash
    export ORACLE_HOME=/home/oracle/oracle_database_client
    export PATH=$ORACLE_HOME/bin:$PATH
    rman target sys/******@//x.x.x.a:1521/ORCL @your_rman_backup_script_file_name
    

    Where @your_rman_backup_script_file_name is the name of the file you just created containing the backup command.