Tuesday, August 2, 2016

Rsync and Backup Ldap Data

#!/bin/sh

HOST=root@172.12.100.55   #eg: ip backup server = 172.12.100.55
SRC=/backup # no slash at end
DST=/ldapbackup/students # no slash at end
TDAY=$(date -j +%Y%m%d) # Current date

#********************* Start Debug **********************************
# For debuging only enable line below:

#set -u # Variables that are not set are errors
#set -x # Print commands when executed
#/usr/bin/touch -t `date -j -v -744H '+%Y%m%d%H%M'` "$SRC"/test-30day-older.txt  # create test file older than 30 days
/usr/bin/find /backup/ -type f -mtime +60 -delete #delete file older than 60 days

#******************** End Debug *************************************

#******* Backup openldap config /usr/local/etc/openldap ******#
#/usr/local/bin/rsync -az /usr/local/etc/openldap/ root@172.12.100.55:/ldapbackup/config/students/


#******* Backup OpenLdap Data & Compress ******#
/usr/local/sbin/slapcat | /usr/bin/gzip > "$SRC"/StudentLdap.$TDAY.gz


#***** Create MD5 File for verification ********#
/sbin/md5 "$SRC"/StudentLdap.$TDAY.gz > "$SRC"/StudentLdap.$TDAY.md5


#******* Set File Permission (allow only root) ******#
/bin/chmod 0600 "$SRC"/StudentLdap.$TDAY.*


#******* Find File older than 31 days and write to log file ******#
/usr/bin/find "$SRC"/ -type f -mtime +31  > "$SRC"/older_log.txt


#******* Run Rsync and copy backup to $HOST:$DST  and --delete to delete files which is no longer in source
/usr/local/bin/rsync --delete -az /backup/ "$HOST":"$DST"/


#******* Enable this and disable above line if need verbose
#/usr/local/bin/rsync -avz /backup/ "$HOST":"$DST"/

No comments:

Post a Comment