LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 02-19-2020, 05:27 AM   #1
edpksrtc
LQ Newbie
 
Registered: Apr 2019
Posts: 15

Rep: Reputation: Disabled
schedule a bash script to move recent/latest dump files from server(rhel 5.7) system to another system(rhel 7.5)


hello all,

i am a newbie in Linux OS , hence need help in below problem.

i have below bash script where i have been taking whole sys user oracle backup and storing it in server itself.

ie,



#!/bin/bash
# file : /home/oracle/app/expbkp_TESTONE.sh
# description : run export backup to localdisk
##########################
##### Variables #######
##########################
RUNTIME=`date '+%H%M_%d%m%Y'`
RUNDATE=`date '+%d%m%Y'`
export LD_LIBRARY_PATH=/home/oracle/app/oracle/product/11.2.0/dbhome_1/lib
export ORACLE_SID=oracle
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:${ORACLE_HOME}/bin
# start the Export backup
expdp "/ as sysdba" directory=EXP_IMP_DIR dumpfile=${ORACLE_SID}_tmk_${RUNTIME}.dmp logfile=${ORACLE_SID}_tmk_${RUNTIME}.log full=y
#########################################################################
#Removing 3 days old dump files
find /home/oracle/expdp_impdp_oracle -mtime +2 -exec rm {} \;



As of date, i have been using scp to manually copy/move recent/latest dump files from host server(rhel 5.7) to backup system (rhel 7.5).

i need help in writing bash script to automate the copying/moving of recent/latest dump files from host server (rhel 5.7) to another system (rhel 7.5).

thanks in advance!!!
 
Old 02-19-2020, 02:19 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,987

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
probably you can add that scp command at the end of this script.
 
1 members found this post helpful.
Old 02-20-2020, 01:08 AM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
As pan64 suggests, you could modify your script (modifications in blue):
Code:
#!/bin/bash
# file : /home/oracle/app/expbkp_TESTONE.sh
# description : run export  backup to localdisk
##########################
##### Variables #######
##########################
RUNTIME=`date '+%H%M_%d%m%Y'`
RUNDATE=`date '+%d%m%Y'`
export LD_LIBRARY_PATH=/home/oracle/app/oracle/product/11.2.0/dbhome_1/lib
export ORACLE_SID=oracle
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:${ORACLE_HOME}/bin
DUMPFILE={ORACLE_SID}_tmk_${RUNTIME}.dmp
# start the  Export backup
expdp "/ as sysdba"  directory=EXP_IMP_DIR dumpfile=$DUMPFILE  logfile=${ORACLE_SID}_tmk_${RUNTIME}.log  full=y
#########################################################################
#Removing 3  days old dump files
find /home/oracle/expdp_impdp_oracle  -mtime +2 -exec rm {} \;

scp $DUMPFILE rhel7-5-server:/whereeverthedumpsgo
Alternatively, after running the original script, use rsync to copy dump files to the RHEL7.5 server. rsync is great at only copying what is not on the destination already. I would need a few additional minutes to dig out the required command line options.

Alternatively, explore whether the expdp program support remote destinations.

It does worry me a little that your script is named TESTONE...
 
1 members found this post helpful.
Old 02-20-2020, 02:31 AM   #4
edpksrtc
LQ Newbie
 
Registered: Apr 2019
Posts: 15

Original Poster
Rep: Reputation: Disabled
sir,
i have been using this below scp command

scp oracle_tmk_2200_19022020.dmp oracle_tmk_2200_19022020.log root@10.0.1.145:/home/ksrtc/bkp


but by using this command i need to specify which file i am transferring to the other system, i need script which takes latest (dump and log) files to be copied/moved from rhel 5.7 server system to rhel 7.5 backup system.

thanks
 
Old 02-20-2020, 02:40 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,987

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
yes, that was described in post #3
Code:
DUMPFILE={ORACLE_SID}_tmk_${RUNTIME}.dmp
LOGFILE=${ORACLE_SID}_tmk_${RUNTIME}.log
# start the  Export backup
expdp "/ as sysdba"  directory=EXP_IMP_DIR dumpfile=$DUMPFILE  logfile=$LOGFILE  full=y
#########################################################################
#Removing 3  days old dump files
find /home/oracle/expdp_impdp_oracle  -mtime +2 -exec rm {} \;

scp $DUMPFILE $LOGFILE root@10.0.1.145:/home/ksrtc/bkp
 
1 members found this post helpful.
Old 02-20-2020, 03:14 AM   #6
edpksrtc
LQ Newbie
 
Registered: Apr 2019
Posts: 15

Original Poster
Rep: Reputation: Disabled
okay sir,,

will try that and will let you all know,,, thanks a lot !
 
Old 02-20-2020, 03:43 AM   #7
edpksrtc
LQ Newbie
 
Registered: Apr 2019
Posts: 15

Original Poster
Rep: Reputation: Disabled
Master table "SYS"."SYS_EXPORT_FULL_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_FULL_01 is:
/home/oracle/expdp_impdp_oracle/oracle_tmk_1453_20022020.dmp
Job "SYS"."SYS_EXPORT_FULL_01" successfully completed at 14:55:46

oracle_tmk_1453_20022020.dmp: No such file or directory
oracle_tmk_1453_20022020.log: No such file or directory



sir ,

after running the bash script backup file is saving in the given directory, but for scp command that directory is not getting looked up!
 
Old 02-20-2020, 06:29 AM   #8
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by edpksrtc View Post
for scp command that directory is not getting looked up!
You need to specify the full pathname to the dump file.

Can you share the current script? Use code tags for better readability.

Last edited by berndbausch; 02-20-2020 at 06:31 AM.
 
1 members found this post helpful.
Old 02-28-2020, 05:56 AM   #9
edpksrtc
LQ Newbie
 
Registered: Apr 2019
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
You need to specify the full pathname to the dump file.

Can you share the current script? Use code tags for better readability.


#!/bin/bash
# file : /home/oracle/app/expbkp_TESTONE.sh
# description : run export backup to localdisk
##########################
##### Variables #######
##########################
RUNTIME=`date '+%H%M_%d%m%Y'`
RUNDATE=`date '+%d%m%Y'`
export LD_LIBRARY_PATH=/home/oracle/app/oracle/product/11.2.0/dbhome_1/lib
export ORACLE_SID=oracle
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:${ORACLE_HOME}/bin
DUMPFILE=${ORACLE_SID}_tmk_${RUNTIME}.dmp
LOGFILE=${ORACLE_SID}_tmk_${RUNTIME}.log
# start the Export backup
expdp "/ as sysdba" directory=EXP_IMP_DIR dumpfile=$DUMPFILE logfile=$LOGFILE full=y
#########################################################################
#Removing 3 days old dump files
find /home/oracle/expdp_impdp_oracle -mtime +2 -exec rm {} \;

scp $DUMPFILE $LOGFILE root@10.0.1.145:/home/ksrtc/bkp



after running above scripts , i am getting the error as below while sending the latest file to another system through scp


Dump file set for SYS.SYS_EXPORT_FULL_01 is:
/home/oracle/expdp_impdp_oracle/oracle_tmk_1453_20022020.dmp
Job "SYS"."SYS_EXPORT_FULL_01" successfully completed at 14:55:46

oracle_tmk_1453_20022020.dmp: No such file or directory
oracle_tmk_1453_20022020.log: No such file or directory



the underlined command's are giving the issue while transferring the file to another system
 
Old 02-28-2020, 06:27 AM   #10
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,483

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
Try the change in blue:

Code:
#!/bin/bash
# file : /home/oracle/app/expbkp_TESTONE.sh
# description : run export  backup to localdisk
##########################
##### Variables #######
##########################
RUNTIME=`date '+%H%M_%d%m%Y'`
RUNDATE=`date '+%d%m%Y'`
export LD_LIBRARY_PATH=/home/oracle/app/oracle/product/11.2.0/dbhome_1/lib
export ORACLE_SID=oracle
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:${ORACLE_HOME}/bin
DUMPFILE=${ORACLE_SID}_tmk_${RUNTIME}.dmp
LOGFILE=${ORACLE_SID}_tmk_${RUNTIME}.log
# start the  Export backup
expdp "/ as sysdba"  directory=EXP_IMP_DIR dumpfile=$DUMPFILE  logfile=$LOGFILE  full=y
#########################################################################
#Removing 3  days old dump files
find /home/oracle/expdp_impdp_oracle  -mtime +2 -exec rm {} \;

cd /home/oracle/expdp_impdp_oracle

scp $DUMPFILE $LOGFILE root@10.0.1.145:/home/ksrtc/bkp
 
1 members found this post helpful.
Old 02-28-2020, 06:44 AM   #11
edpksrtc
LQ Newbie
 
Registered: Apr 2019
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
Try the change in blue:

Code:
#!/bin/bash
# file : /home/oracle/app/expbkp_TESTONE.sh
# description : run export  backup to localdisk
##########################
##### Variables #######
##########################
RUNTIME=`date '+%H%M_%d%m%Y'`
RUNDATE=`date '+%d%m%Y'`
export LD_LIBRARY_PATH=/home/oracle/app/oracle/product/11.2.0/dbhome_1/lib
export ORACLE_SID=oracle
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:${ORACLE_HOME}/bin
DUMPFILE=${ORACLE_SID}_tmk_${RUNTIME}.dmp
LOGFILE=${ORACLE_SID}_tmk_${RUNTIME}.log
# start the  Export backup
expdp "/ as sysdba"  directory=EXP_IMP_DIR dumpfile=$DUMPFILE  logfile=$LOGFILE  full=y
#########################################################################
#Removing 3  days old dump files
find /home/oracle/expdp_impdp_oracle  -mtime +2 -exec rm {} \;

cd /home/oracle/expdp_impdp_oracle

scp $DUMPFILE $LOGFILE root@10.0.1.145:/home/ksrtc/bkp

sir i changed this code scp $DUMPFILE $LOGFILE root@10.0.1.145:/home/ksrtc/bkp to scp /home/oracle/expdp_impdp_oracle/$DUMPFILE /home/oracle/expdp_impdp_oracle/$LOGFILE root@10.0.1.145:/home/ksrtc/bkp


but here the password for the destination machine is been asked , how to automate and the ssh password , which will take the password automatically and tranfer the dump file to destination system

Last edited by edpksrtc; 02-28-2020 at 06:46 AM.
 
Old 02-28-2020, 06:47 AM   #12
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,483

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
Use SSH key pairs for authentication not passwords. There's plenty of resources on how to do this, there's even one in my sig.
 
1 members found this post helpful.
Old 02-28-2020, 06:50 AM   #13
edpksrtc
LQ Newbie
 
Registered: Apr 2019
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
Use SSH key pairs for authentication not passwords. There's plenty of resources on how to do this, there's even one in my sig.

okay sir, thanks for your valuable help! helped me a lot!
 
Old 02-28-2020, 06:58 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,987

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
see post #8
Code:
#!/bin/bash
EXP_IMP_DIR=/home/oracle/expdp_impdp_oracle
# file : /home/oracle/app/expbkp_TESTONE.sh
.....

DUMPFILE=${ORACLE_SID}_tmk_${RUNTIME}.dmp
LOGFILE=${ORACLE_SID}_tmk_${RUNTIME}.log
# start the Export backup
expdp "/ as sysdba" directory=$EXP_IMP_DIR dumpfile=$DUMPFILE logfile=$LOGFILE full=y

scp $EXP_IMP_DIR/$DUMPFILE $EXP_IMP_DIR/$LOGFILE root@10.0.1.145:/home/ksrtc/bkp
probably works better
 
1 members found this post helpful.
Old 02-28-2020, 07:48 AM   #15
edpksrtc
LQ Newbie
 
Registered: Apr 2019
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
see post #8
Code:
#!/bin/bash
EXP_IMP_DIR=/home/oracle/expdp_impdp_oracle
# file : /home/oracle/app/expbkp_TESTONE.sh
.....

DUMPFILE=${ORACLE_SID}_tmk_${RUNTIME}.dmp
LOGFILE=${ORACLE_SID}_tmk_${RUNTIME}.log
# start the Export backup
expdp "/ as sysdba" directory=$EXP_IMP_DIR dumpfile=$DUMPFILE logfile=$LOGFILE full=y

scp $EXP_IMP_DIR/$DUMPFILE $EXP_IMP_DIR/$LOGFILE root@10.0.1.145:/home/ksrtc/bkp
probably works better

sir, everything is working fine except for password! after all the exporting , the scp command is asking for password to transfer the file. though the ssh keys have been created . while manually using scp command in terminal, the password is not been asked ,, but the scp command at last of the bash script, the password is been asked, here how to automate, so that the password in not asked for the below scp command

scp /home/oracle/expdp_impdp_oracle/$DUMPFILE /home/oracle/expdp_impdp_oracle/$LOGFILE root@10.0.1.145:/home/ksrtc/bkp
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Tentative Schedule Meets Tentative Schedule For ATO LXer Syndicated Linux News 0 08-11-2014 04:10 PM
puppy thoughts after having a recent look see -- given recent developments .. jonyo Puppy 0 11-29-2011 08:45 PM
BASH script to move files/folders to either the .Trash file or to another direcotry bettsy583 Linux - Newbie 13 12-03-2010 03:41 AM
[SOLVED] Bash script needed to move files to another folder. No_one_knows_me Linux - General 28 01-07-2010 10:29 PM
LXer: Schedule Tasks Using Gnome-schedule (cron & at GUI) LXer Syndicated Linux News 0 07-28-2007 12:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 09:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration