0

I have a service set up in C#/.NET Core and part of its functionality is to launch RMAN for Oracle at a specified time each day. These functionalities all work perfectly running as the Oracle user but not as root or running as systemd(even if I include the parameter to run as oracle in the init file).

Error when trying to run RMAN as root: Error as Root

ORA-12162: TNS:net service name is incorrectly specified

The code in C#:

string oraHome = Environment.GetEnvironmentVariable("ORACLE_HOME");
            //execute powershell cmdlets or scripts using command arguments as process
            ProcessStartInfo processInfo = new ProcessStartInfo
            {
                FileName = $"{oraHome}/bin/rman",
                Arguments = $"NOCATALOG TARGET  / CMDFILE {RMANObjects.Backup}RMAN_{RMANObjects.sn}.rcv LOG {RMANObjects.Backup}backup_log_{RMANObjects.sn}.txt",
                RedirectStandardError = true,
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            //start powershell process using process start info
            Process process = new Process();
            process.StartInfo = processInfo;
            process.Start();

RMANandLogMover init/service file

[Unit]
Description=RMANandLogMover
DefaultDependencies=no


[Service]
Type=notify
WorkingDirectory=/home/oracle/app/RMANandLogMover/8.25Logmover
ExecStart=/home/oracle/app/RMANandLogMover/8.25Logmover/RMANandLogMover
Environment=ORACLE_HOME=/home/oracle/app/product/19.0.0/dbhome_1
User=oracle
Group=backupdba
RemainAfterExit=yes


[Install]
WantedBy=default.target
  • why dont you write a simple bash script for it? – Derviş Kayımbaşıoğlu Sep 14 '20 at 15:31
  • 1
    WHY would you want to run rman as anything but the oracle software owner, usually 'oracle'? I can't think of a single good reason. That aside, your environment probably isn't properly set - in particular ORACLE_HOME and ORACLE_SID. – EdStevens Sep 14 '20 at 15:32

1 Answers1

1

the problem here is not all environment variables are set. I suggest you to invoke oraenv first and make sure that you are using oracle's os user, not any other

export ORACLE_HOME=<path>
export ORACLE_SID=orcl
export ORAENV_ASK=NO
. oraenv

first code this, then run RMAN :)

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72