Tool

Mark Batchelor's picture
tool
Reads:

6610

Score:
0
0
 
Comments:

1

eDirectory Backup Script for Linux

Author Info

8 April 2005 - 10:05am
Submitted by: Mark Batchelor

license: 
Free

This is a little script I put together to get backups of eDirectory from a Linux box. NDSBackup is a good utiltity - you can even schedule it, but I had a need to backup multiple trees, and I also did not want to manage backup directories, or archival directories for that matter. So I put together a really quick shell script to do some of that for me.

Usage:

edirbackup.sh [-t][-s]

-t denotes the name of the tree you are going to backup.

-s denotes the server you wish to backup from. (preferebly a replica server)

Example:
edirbackup.sh -t my-tree-name -s myserver.mycompany.com

The script takes a full tree backup, and a seperate backup for the schema on each tree. It then mails each report to whomever you want.
It also handles directory creation past the intitial backup directory. Nothing special, I just did this because I was lazy. :)

AttachmentSize
edirbackup.zip1.29 KB




User Comments

tokeeffefcc's picture

Nice tool

Submitted by tokeeffefcc on 25 October 2011 - 6:26am.

I have updated the script a little for current SLES10sp4 and above to match directory structure with eDir 8.8x.
I use this mainly to backup the NICI files nightly using a cron job. I have placed this in a new folder off the root, \backup, made the script executable and have it run around 11:30 pm which works for us.
It also cleans up after 7 days or whatever you want which I pasted in from other cool tools.

30 23 * * * root /backup/nicibackup.sh

script is as follows:
nicibackup.sh

#!/bin/sh

####################################################
# Name: nicibackup.sh
#
# Author: Novell Cool Solutions
#
# Purpose: To perform full backups of NICI for eDirectory.
# To archive and zip the backups to be
# ready for tape archival.
#
# Change control:
# 1. 8/4/2005 - Created
# 2. 2/15/2011 - Updated script for cleaning up
# self and portability
# 3. 10/04/2011 - Updated script for email notifications
####################################################

usageQuit()
{
cat << "EOF" >&2
Usage: $o [-o output] [-t] [-s]
-t specifies tree to run backup against.
-s specifies the server to run the backup against. (root server is best)
EOF
exit 1
}

# This little section calculates disk space remaining and prints it to the screen. Just in case.
tempfile="/tmp/available.$$"
trap "rm -f $tempfile" exit
cat << 'EOF' > $tempfile
{ sum += $4 }
END { mb = sum / 1024
gb = mb / 1024
printf "%.0f MB (%.2fGB) of available disk space\n", mb, gb
}
EOF

df -k | awk -f $tempfile

backupdir="/var/opt/novell/eDirectory/backup" # Insert the location of the the backups directory
adminname=".your_name.ou.o" # Admin ID in the tree you are backing up
password="your_password" # It needs to go here, flag file for root access only in directory for root access only
tree="your_tree"
bserver="your_server"
backupstreams=-t
overwrite=-w
backupnici=-e
nicipwd=secret
EMAIL1=root
EMAIL2=name1@domain.com
EMAIL3=name2@domain.com

# Get command line arguments
while getopts "o:t:s" arg; do
case "$arg" in
o ) output="$1"; ;;
s ) bserver="$4"; ;;
t ) tree="$2"; ;;
esac
done

mydir="$backupdir/$tree" # Becomes the path to use for backups
myserver="$tree-$bserver-" # Becomes the backup name for clarity

shift $(( $OPTIND - 1 ))

echo "Backing up $tree from server $bserver"

# Generate unique timestamp for each file name
timestamp="$(date +'%m-%d-%I:%M')" # Get timestamp to use on files
echo "Timestamp = $timestamp"

if [ ! -d $mydir ] ; then # Check to see if tree dir exists if not, create it
echo "backup directory doesn't exist. Creating now"
mkdir $backupdir/$tree
fi
if [ ! -d $mydir/logs ] ; then # Check to see if logs dir exists if not, create it
echo "log directory doesn't exist. Creating now"
mkdir $backupdir/$tree/logs
fi

echo "Now Backing up Database in $tree. Please Wait................."
dsbk backup -b -f $backupdir/$tree/$tree$bserver$timestamp.bkup -l $backupdir/$tree/$tree$bserver$timestamp.log $backupstreams $overwrite $backupnici $nicipwd

sleep 10
# Archive files
echo " Archiving $File ..."
tar zcvf $backupdir/$tree/$myserver$timestamp.tgz $backupdir/$tree/$tree$bserver$timestamp.bkup $backupdir/$tree/$tree$bserver$timestamp.log
echo " "

# Now backup the eDirectory NICI

tar cvzfp $backupdir/$tree/edir_nici_$timestamp.tar.gz /etc/opt/novell/nici.cfg /opt/novell/lib/libccs2.so.* /var/opt/novell/nici

tar cvzfp $backupdir/$tree/conf_backup_$timestamp.tar.gz /etc/opt/novell/eDirectory/conf/nds.conf

tar cvzfp $backupdir/$tree/ndsd_script_backup_$timestamp.tar.gz /etc/init.d/ndsd

# I couldn't get the next line to work in my setup
#tar cvzfp $backupdir/$tree/edir_w_permissions.tar.gz /shared/edir/

# Email notice of backup
echo "NICI Backup of $tree $bserver complete at $timestamp. Placed in $backupdir/$tree/$tree.$timestamp." | mail -s "NICI Backup report for $bserver" $EMAIL1,$EMAIL2,$EMAIL3

# Delete unnecessary files
echo " "
echo " Deleting temp files ..."
rm -f $backupdir/$tree/*.bak
rm -f $backupdir/$tree/*.bkup
rm -f $backupdir/$tree/*.log

# Clean up anything older than 7 days, even though you use +5, might be something weird on my systems
# To add more days of archival change the +5 to +N (whatever number you want)

echo "Now purging any backups older than 7 days from the server to save space.."
echo "Please wait....."
find $backupdir/$tree -mtime +5 -exec rm -f {} \;
exit 0
.

© 2013 Novell