NexOSS Backup Scripts

NexOSS Backup Scripts

  • The backup-oss.sh script saves the $NexOSS_HOME directory as a compressed tar file, named NexOSS_backup.YYYYMMDD.tar.gz to the /Backup directory.

  • The scp-oss.sh script copies the backup file to an external server.

The two scripts in this section can be run using Cron to save the $NexOSS_HOME directory as a tar file and then copy the tar file to an external server. The following line is an example Cron configuration.

59 23 * * * . ./.bash_profile; $NexOSS_HOME/../Backup/backup-oss.sh ; $NexOSS_HOME/../Backup/scp-oss.sh

backup-oss.sh

The backup-oss.sh script saves the $NexOSS_HOME directory as a tar file in the /Backup directory.
The name of the tar file (NexOSS_backup.YYYYMMDD.tar.gz) includes a date stamp of when the file was created.

#!/bin/sh
#
# backup-oss.sh
#
### Remove previous NexOSS_backup files from the $NexOSS_HOME/../Backup
### directory.

rm -rf $NexOSS_HOME/../Backup/NexOSS_backup.*.tar.gz

## Create a backup file of the NexOSS configuration in the backup
## directory $NexOSS_HOME/../Backup.  The name of the backup
## file will include the current date.

tar -cvf $NexOSS_HOME/../Backup/NexOSS_backup.`date '+%Y%m%d'`.tar $NexOSS_HOME/*

### Compress the tarball of NexOSS directory backup file in the
### $NexOSS_HOME/../Backup directory.

gzip $NexOSS_HOME/../Backup/NexOSS_backup.`date '+%Y%m%d'`.tar

scp-oss.sh

The scp-oss.sh script uses the Unix secure copy command to copy the NexOSS directory tar file from the /Backup directory to an external server. Follow the configuration directions in the scp-oss.sh script to configure access to the external server.

#!/bin/sh
#
# scp-oss.sh
#
######################################################################
       
# This script enables the client system with the NexOSS_backup file to
# access an external server via ssh securely without the need to enter
# password. This feature enables the client system to perform a secure
# copy (scp) of the NexOSS_backup file to the external server using this
# script, without user intervention.
#
# The UID (username) of the client system that owns the NexOSS_backup
# file must also exist on the external server system that will receive
# the Oracle dump file transfer.
#######################################################################
#######################################################################
# The external server must support public key authentication.
#
# To enable public key authentication add the following lines to 
# /etc/ssh/sshd_config on the external server.
#    RSAAuthentication=yes
#    PubkeyAuthentication=yes
#
# Next, restart the ssh daemon (sshd) on the external server by
# executing the command:
#
### /etc/init.d/sshd restart
#
#######################################################################
#######################################################################
# After restarting sshd, generate a public RSA key on the client system
# and copy it to the list of authorized keys on the external server.
# On the client machine execute (leave passphrase empty):
#
### ssh-keygen -t rsa
#
# This will create public key at /home/your_login/.ssh/id_rsa.pub.
#
#######################################################################
#######################################################################
# Next, copy the public generated key to the external server (for
# example by 'scp' command):
#
### scp /home/your_login/.ssh/id_rsa.pub server_login@server_ip_address:/tmp
#
#######################################################################
#######################################################################
# After the client system’s public key is copied to /tmp/id_rsa.pub of
# the external server, login to the external server and perform the
# following operation to add the client system's publick key to the
# list of authorized keys by executing the command:
#
### mkdir /home/server_login/.ssh  (only if it's needed)
#
### cat /tmp/id_rsa.pub >> /home/server_login/.ssh/authorized_keys
#
#######################################################################
#######################################################################
# When done, try to login to server from client:
#
### ssh server_login@server_ip_address
#
# If you can successfully ssh into the server from the client, then
# the client is ready for scp without a password from this script.
#######################################################################
#
# Edit the variables shown below to match your systems.
#
export SCP=/usr/bin/scp
export OUTFILE_DIR=/home/ossadmin/OSS/Backup
export OUTFILE=NexOSS_backup.*.tar.gz
export REMOTE_USER=ossadmin
export SERVER=172.16.4.xx
export INFILE_DIR=/home/ossadmin/ossdump
#
$SCP $OUTFILE_DIR/$OUTFILE $REMOTE_USER@$SERVER:$INFILE_DIR