Just input schema name and it will take backup of schema.
vi backup_schema.sh
#!/bin/sh
# Set environment variables
export ORACLE_SID=testdb1
export ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/test-db
export PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/lib:/usr/ccs/bin:$ORACLE_HOME/OPatch
DATEFORMAT=`date +%Y%m%d`
# Check if schema name is passed as an argument
if [ -z "$1" ]; then
echo "Schema name is required. Exiting..." >> nohup.out
exit 1
fi
# Assign the first argument as the schema name
schema_name=$1
# Data Pump export command
echo "Starting backup for schema $schema_name at $(date)" >> nohup.out
expdp \"/ as sysdba\" directory=OBACKUP dumpfile=expdp_${schema_name}_`echo $DATEFORMAT`.dmp logfile=expdp_${schema_name}_`echo $DATEFORMAT`.log schemas=$schema_name parallel=8 cluster=n flashback_time=systimestamp >> nohup.out 2>&1
# Check if the expdp command was successful
if [ $? -eq 0 ]; then
echo "Backup of schema $schema_name completed successfully at $(date)." >> nohup.out
else
echo "Backup failed for schema $schema_name. Please check the log file for details." >> nohup.out
exit 1
fi
Use below command to run the script ...
nohup ./backup_schema.sh schemaname &
No comments:
Post a Comment