Restore Ranger Admin Database

You must restore the Ranger Admin database for MySQL and PostgreSQL.

You must stop Ranger Admin and KMS service if they are running. Restore Ranger admin databases.

MySQL

Perform the following steps to restore a database.
  1. Delete the existing Database.
  2. Create an empty new database on the database host.
  3. Restore the database using below msyql command.
    mysql -u root
    drop database ranger;
    create database ranger;
    GRANT ALL PRIVILEGES ON ranger.* TO 'rangeradmin'@'localhost';
    $ mysql -u [username] -p  existing_empty_db_name < dump_fileName.sql
Example
mysql -u rangeradmin -p rangeradmin < /root/backups/ranger/db/admin/ranger.sql

Press the Enter key. Type the database password when the password prompts.

POSTGRES

Perform the following steps to restore a database.

  1. Delete an existing Database.
  2. Create an empty new database in its place.
  3. Run the below command on postgres db host.
    dropdb -U owner_username dbname; [Enter db owner password at the prompt]

    Example

    dropdb -U rangeradmin ranger;
    su  -  postgres
    psql 
    create database ranger;
    ALTER DATABASE ranger OWNER TO rangeradmin; 
    \q
    exit
    psql -U rangeradmin ranger < /root/backups/ranger/db/admin/ranger.sql 

    Press the Enter key. Type the database password when the password prompts.

    Oracle

    Set the path to Oracle home if required :

    export ORACLE_HOME=/opt/oracle/product/12.2.0
    export PATH=${PATH}:${ORACLE_HOME}/bin
    export ORACLE_SID=orcl12c
    Restore ranger admin database.
    rm -rf del_admin_tbl_cmd.sql
    sqlplus -s rangeradmin/rangeradmin << EOF 
            			spool on
            			spool del_admin_tbl_cmd.sql
            			SELECT 'DROP TABLE "' || TABLE_NAME || '" CASCADE CONSTRAINTS;' FROM user_tables
            			union ALL
            			select 'drop '||object_type||' '|| object_name || ';' from user_objects 
            			where object_type in ('VIEW','PACKAGE','SEQUENCE', 'PROCEDURE', 'FUNCTION')
            			union ALL
            			SELECT 'drop '
            			||object_type
            			||' '
            			|| object_name
            			|| ' force;'
            			FROM user_objects
            			WHERE object_type IN ('TYPE');
            			spool off
            			@del_admin_tbl_cmd.sql
            			exit;   
                                 EOF
    Type the database password when the password prompts and then run the following command:
    imp rangeradmin/rangeradmin file=backups/ranger/db/admin/orcl12c.sql log=backups/ranger/db/admin/restore.log