Thursday, December 31, 2009

Backup Script OpenLDAP

Malam-malam ga bisa tidur, iseng2 lihat backup-an script di server LDAP. Jadi inget pengalaman minggu yang lalu dimana database user ldap corrupt, untung setiap hari di backup jadi tinggal re-install OpenLDAP trus di restore. Berikut adalah script backup sederhana ang saya buat ;

#!/bin/bash
DATADIR="/var/backup/ldap"
DATE=$(date +%Y-%m-%d)
# Backup LDAP
echo "Backup LDAP"
slapcat -l $DATADIR/ldap-backup-$DATE.ldif
echo "Compress LDAP backup files"
gzip -9 $DATADIR/ldap-backup-$DATE.ldif
echo "Delete backup file older than 5 days"
# Delete old file
find $DATADIR/*.gz -mtime +5 -exec rm {} \;echo "Done!"
exit


Setelah itu simpan dengan nama file backup-ldap.sh dan tempatkan di folder /etc/cron.daily/, script tersebut saya jalankan setiap hari menggunakan crontab.

Untuk restore file tersebut sebelumnya di extract terlebih dahulu ;
#gunzip ldap-backup-2009-12-30.ldif.gz

lalu restore dengan perintah ;


#slapadd -v -c -l ldap-backup-2009-12-30.ldif -f /etc/openldap/slapd.conf

Setelah itu restart service openldap.

Done

1 comment:

Satchel said...

Now I feel stupid. That's cerlaed it up for me