OpenLDAP 数据备份脚本


#!/bin/sh

bak_dir=/opt
bak_date=$(date "+%Y%m%d")
cmd_dir=$(
	cd $(dirname $0)
	pwd
)

cd $bak_dir
mkdir openldap-bak-$bak_date
mkdir openldap-bak-$bak_date/db
mkdir openldap-bak-$bak_date/etc

cp -r /var/lib/ldap openldap-bak-$bak_date/db/
cp -r /etc/openldap openldap-bak-$bak_date/etc/

tar zcf openldap-bak-${bak_date}.tar.gz openldap-bak-$bak_date
rm -rf openldap-bak-$bak_date

# 保留90天的历史备份数据
date >>$cmd_dir/openldap-bak-rm.log
for i in $(find . -maxdepth 1 -mindepth 1 -mtime +90 -name "openldap-bak-*" | sed 's#./##'); do
	echo "rm -rf $i" >>$cmd_dir/openldap-bak-rm.log
	rm -rf $i
done
echo "------------------------------------------------------------" >>$cmd_dir/openldap-bak-rm.log

# 异地备份
scp -r openldap-${bak_date}.tar.gz root@192.168.0.100:/opt