Backup scripts for eDirectory on Linux

0 Likes
by Brad Bartholomew

Here are two scripts for doing a backup of eDirectory on Linux using either dsbk or ndsbackup. Download the file and use the following instructions to implement.



Installation instructions:




  1. Copy the edirbkup.tgz file to the root directory '/'. Extract the backup directory and scripts by executing the following command:
       #  tar zxvf edirbkup.tgz


  • Modify the scripts by changing the variables to be specific to your server and eDirectory tree.
       #  vi dsbkup.sh
    # vi ndsbackup.sh


  • Add an entry in crontab to schedule the script to run automatically. To run nightly you may use something like this:
       0 23 * * * /backup/dsbkup.sh
    30 23 * * * /backup/ndsbackup.sh



The scripts are designed to keep only the 7 most current backups. You can modify it to meet your needs.


Tags:

Labels:

How To-Best Practice
Collateral
Comment List
Parents
  • Thanks for the scripts! I've tested both the original and tokeeff's, had a few errors on my servers, so I made a few minor adjustments that helped. I hope it displays properly.

    dsbkup.sh


    #!/bin/bash

    . /opt/novell/eDirectory/bin/ndspath

    # Variables
    CDate=`date +%Y%m%d`
    tree=!yourTree!
    server=$HOSTNAME
    file=$tree$server$CDate
    backupdir=/backup/dsbkup
    EMAIL1=root

    # Generate unique timestamp for each file name
    timestamp=”$(date +’%m-%d-%I:%M’)” #get timestamp to use on files
    echo “Timestamp = $timestamp”

    # Create Tree backup dir
    mkdir /backup
    mkdir /backup/dsbkup
    mkdir $backupdir/$tree

    # Backup eDirectory
    echo ” Starting backup of eDirectory on $server …”
    dsbk backup -b -f $backupdir/$tree/$file.bkup -l $backupdir/$tree/$file.log -t -w

    # Check to see if backup is complete
    sleep 10
    i=`ls -l $backupdir/$tree/$file.bkup | cut -d' ' -f6`
    sleep 10
    i2=`ls -l $backupdir/$tree/$file.bkup | cut -d' ' -f6`

    while [ $i -ne $i2 ]
    do
    sleep 60
    i=`ls -l $backupdir/$tree/$file.bkup | cut -d' ' -f6`
    sleep 10
    i2=`ls -l $backupdir/$tree/$file.bkup | cut -d' ' -f6`
    done

    # Archive files
    echo ” Archiving $file …”
    tar zcvf $backupdir/$tree/$file.tgz $backupdir/$tree/$file.bkup $backupdir/$tree/$file.log

    # Delete unnecessary files
    echo ” Deleting temp files …”
    rm -f $backupdir/$tree/$file.bkup $backupdir/$tree/$file.log

    # Delete files older than 30 days
    echo ” Deleting files older than 30 days …”
    find $backupdir/$tree/ -name ‘*.tgz’ -mtime +30 >> /tmp/dsbackup.tmp
    cat /tmp/dsbackup.tmp | while read delfil
    do
    rm -f ${delfil}
    done
    [[ -s /tmp/dsbackup.tmp ]] && { rm /tmp/dsbackup.tmp ;}

    echo ” Backup script complete.”

    # Email notice of backup
    echo "eDir dsBackup of" $tree $server "complete at" $timestamp". Placed in "$backupdir/$tree/$tree.$timestamp"." | mail -s "eDir dsBackup report for "$server $EMAIL1

    # End of Script




    ndsbackup.sh


    #!/bin/bash

    . /opt/novell/eDirectory/bin/ndspath

    # Variables
    User=!youruser!
    Pwd=!yourpassword!
    tree=!yourTree!
    CDate=`date +%Y%m%d`
    server=$HOSTNAME
    file=SafetyBackup$tree$server$CDate
    backupdir=/backup/ndsbackup
    CDir=/etc/opt/novell/eDirectory/conf/nds.conf
    JPath=/opt/novell/eDirectory/lib/nds-modules/embox/jre/bin
    EMAIL1=root

    # Generate unique timestamp for each file name
    timestamp=”$(date +’%m-%d-%I:%M’)” #get timestamp to use on files
    echo “Timestamp = $timestamp”

    # Create Tree backup dir
    mkdir /backup
    mkdir /backup/ndsbackup
    mkdir $backupdir/$tree
    mkdir $backupdir/$tree/logs

    # Backup eDirectory
    echo Starting backup of eDirectory on $server …
    ndsbackup cvf $backupdir/$tree/$file.bak -a $User -p $Pwd
    tar zcvf $backupdir/$tree/$file.tgz $backupdir/$tree/$file.bak

    # Now lets backup the eDirectory schema
    ndsbackup cvf $backupdir/$tree/$file.schema.bak $server -a $User -p $Pwd Schema >> $backupdir/$tree/logs/$file.schema.log
    tar zcvf $backupdir/$tree/$file.schema.tgz $backupdir/$tree/$file.schema.bak

    # Delete unnecessary files
    echo ” Deleting temp files …”
    rm -f $backupdir/$tree/*.bak

    # Delete files older than 30 days
    echo ” Deleting files older than 30 days …”
    find $backupdir/$tree/ -name ‘*.tgz’ -mtime +30 >> /tmp/ndsbackup.tmp
    cat /tmp/ndsbackup.tmp | while read delfil
    do
    rm ${delfil}
    done
    [[ -s /tmp/ndsbackup.tmp ]] && { rm /tmp/ndsbackup.tmp ;}

    # Delete log files older than 30 days
    echo ” Deleting log files older than 30 days …”
    find $backupdir/$tree/logs/ -name ‘*.log’ -mtime +30 >> /tmp/ndsbackuplog.tmp
    cat /tmp/ndsbackuplog.tmp | while read delfil
    do
    rm ${delfil}
    done
    [[ -s /tmp/ndsbackuplog.tmp ]] && { rm /tmp/ndsbackuplog.tmp ;}

    echo ” Backup script complete.”

    # Email notice of backup
    echo "nds Backup of "$tree $server" complete at "$timestamp". Placed in "$backupdir/$tree/$tree.$timestamp"." | mail -s "nds Backup report for $server" $EMAIL1

    # End of Script
Comment
  • Thanks for the scripts! I've tested both the original and tokeeff's, had a few errors on my servers, so I made a few minor adjustments that helped. I hope it displays properly.

    dsbkup.sh


    #!/bin/bash

    . /opt/novell/eDirectory/bin/ndspath

    # Variables
    CDate=`date +%Y%m%d`
    tree=!yourTree!
    server=$HOSTNAME
    file=$tree$server$CDate
    backupdir=/backup/dsbkup
    EMAIL1=root

    # Generate unique timestamp for each file name
    timestamp=”$(date +’%m-%d-%I:%M’)” #get timestamp to use on files
    echo “Timestamp = $timestamp”

    # Create Tree backup dir
    mkdir /backup
    mkdir /backup/dsbkup
    mkdir $backupdir/$tree

    # Backup eDirectory
    echo ” Starting backup of eDirectory on $server …”
    dsbk backup -b -f $backupdir/$tree/$file.bkup -l $backupdir/$tree/$file.log -t -w

    # Check to see if backup is complete
    sleep 10
    i=`ls -l $backupdir/$tree/$file.bkup | cut -d' ' -f6`
    sleep 10
    i2=`ls -l $backupdir/$tree/$file.bkup | cut -d' ' -f6`

    while [ $i -ne $i2 ]
    do
    sleep 60
    i=`ls -l $backupdir/$tree/$file.bkup | cut -d' ' -f6`
    sleep 10
    i2=`ls -l $backupdir/$tree/$file.bkup | cut -d' ' -f6`
    done

    # Archive files
    echo ” Archiving $file …”
    tar zcvf $backupdir/$tree/$file.tgz $backupdir/$tree/$file.bkup $backupdir/$tree/$file.log

    # Delete unnecessary files
    echo ” Deleting temp files …”
    rm -f $backupdir/$tree/$file.bkup $backupdir/$tree/$file.log

    # Delete files older than 30 days
    echo ” Deleting files older than 30 days …”
    find $backupdir/$tree/ -name ‘*.tgz’ -mtime +30 >> /tmp/dsbackup.tmp
    cat /tmp/dsbackup.tmp | while read delfil
    do
    rm -f ${delfil}
    done
    [[ -s /tmp/dsbackup.tmp ]] && { rm /tmp/dsbackup.tmp ;}

    echo ” Backup script complete.”

    # Email notice of backup
    echo "eDir dsBackup of" $tree $server "complete at" $timestamp". Placed in "$backupdir/$tree/$tree.$timestamp"." | mail -s "eDir dsBackup report for "$server $EMAIL1

    # End of Script




    ndsbackup.sh


    #!/bin/bash

    . /opt/novell/eDirectory/bin/ndspath

    # Variables
    User=!youruser!
    Pwd=!yourpassword!
    tree=!yourTree!
    CDate=`date +%Y%m%d`
    server=$HOSTNAME
    file=SafetyBackup$tree$server$CDate
    backupdir=/backup/ndsbackup
    CDir=/etc/opt/novell/eDirectory/conf/nds.conf
    JPath=/opt/novell/eDirectory/lib/nds-modules/embox/jre/bin
    EMAIL1=root

    # Generate unique timestamp for each file name
    timestamp=”$(date +’%m-%d-%I:%M’)” #get timestamp to use on files
    echo “Timestamp = $timestamp”

    # Create Tree backup dir
    mkdir /backup
    mkdir /backup/ndsbackup
    mkdir $backupdir/$tree
    mkdir $backupdir/$tree/logs

    # Backup eDirectory
    echo Starting backup of eDirectory on $server …
    ndsbackup cvf $backupdir/$tree/$file.bak -a $User -p $Pwd
    tar zcvf $backupdir/$tree/$file.tgz $backupdir/$tree/$file.bak

    # Now lets backup the eDirectory schema
    ndsbackup cvf $backupdir/$tree/$file.schema.bak $server -a $User -p $Pwd Schema >> $backupdir/$tree/logs/$file.schema.log
    tar zcvf $backupdir/$tree/$file.schema.tgz $backupdir/$tree/$file.schema.bak

    # Delete unnecessary files
    echo ” Deleting temp files …”
    rm -f $backupdir/$tree/*.bak

    # Delete files older than 30 days
    echo ” Deleting files older than 30 days …”
    find $backupdir/$tree/ -name ‘*.tgz’ -mtime +30 >> /tmp/ndsbackup.tmp
    cat /tmp/ndsbackup.tmp | while read delfil
    do
    rm ${delfil}
    done
    [[ -s /tmp/ndsbackup.tmp ]] && { rm /tmp/ndsbackup.tmp ;}

    # Delete log files older than 30 days
    echo ” Deleting log files older than 30 days …”
    find $backupdir/$tree/logs/ -name ‘*.log’ -mtime +30 >> /tmp/ndsbackuplog.tmp
    cat /tmp/ndsbackuplog.tmp | while read delfil
    do
    rm ${delfil}
    done
    [[ -s /tmp/ndsbackuplog.tmp ]] && { rm /tmp/ndsbackuplog.tmp ;}

    echo ” Backup script complete.”

    # Email notice of backup
    echo "nds Backup of "$tree $server" complete at "$timestamp". Placed in "$backupdir/$tree/$tree.$timestamp"." | mail -s "nds Backup report for $server" $EMAIL1

    # End of Script
Children
No Data
Related
Recommended