LDAP 備份還原 備份 OpenLDAP 中數(shù)據(jù)備份一般分為三種方式,一種通過 slapcat 指令進行備份,一種通過 phpLDAPadmin 控制臺進行備份,另一種通過數(shù)據(jù)目錄來實現(xiàn)備份。本次只介紹最簡單直接的辦法–使用 slapcat slapcat slapcat幫助文檔 備份腳本 #!/usr/bin/env bash LDAPBK=ldap-$( date +%Y%m%d-%H ).ldif BACKUPDIR=/data/ldap_backups BACKUP_EXEC=`which slapcat` PACKAGE=`which gzip` checkdir(){ if [ ! -d "$BACKUPDIR" ]; then mkdir -p ${BACKUPDIR} fi } backuping(){ echo "Backup Ldap Start...." ${BACKUP_EXEC} -v -l ${BACKUPDIR}/${LDAPBK} ${PACKAGE} -9 $BACKUPDIR/$LDAPBK } checkdir backuping 1 2 定時備份 具體時間自己把控 crontab -e 00 */2 * * * /path/ldap_backup.sh 1 2 還原 模擬數(shù)據(jù)丟失 # 獲取所有用戶配置條目 ldapsearch -x -Z -LLL -H ldap://172.16.10.220 -b 'ou=People,dc=laoshiren,dc=com' | wc -l 106 # 清空所有所有條目 ldapdelete -x -D "cn=manager,dc=laoshiren,dc=com" -w FCzxpJWCccuB -r "dc=laoshiren,dc=com" # 確認條目 ldapsearch -x -Z -LLL -H ldap://172.16.10.220 -b 'ou=People,dc=laoshiren,dc=com' | wc -l 0 1 還原數(shù)據(jù) systemctl stop slapd && systemctl status slapd # 清空原openldap數(shù)據(jù) rm -fr /var/lib/ldap/* /usr/sbin/slapadd -l /data/ldap_backups/ldap-20190109-21.ldif # 輸出 5c36b84d The first database does not allow slapadd; using the first available one (2) 5c36b84d hdb_db_open: warning - no DB_CONFIG file found in directory /var/lib/ldap: (2). Expect poor performance for suffix "dc=laoshiren,dc=com". _#################### 100.00% eta none elapsed none fast! Closing DB... # 拷貝數(shù)據(jù)配置文件 cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG # 賦權(quán) chown ldap:ldap -R /var/lib/ldap/ # 啟動 slapd systemctl start slapd && systemctl status slapd 1 驗證數(shù)據(jù) # 驗證條目 ldapsearch -x -Z -LLL -H ldap://172.16.10.220 -b 'ou=People,dc=laoshiren,dc=com' | wc -l 106 # 驗證登錄 ssh -i ~/.ssh/id_rsa clin@172.16.10.10 Last login: Wed Jan 9 21:43:07 2019 from 172.16.10.1 -sh-4.2$ 1 2 3 4 5 6 7 恢復(fù)完成 原文:https://blog.csdn.net/u011607971/article/details/86221860 |
|