Skip to content

Commit

Permalink
ldap---56---自动添加 crontab 定时备份任务
Browse files Browse the repository at this point in the history
  • Loading branch information
Eron-Liu committed Jan 31, 2019
1 parent 175e084 commit bfd2da1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 04-add_plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- hosts: server
roles:
- { role: ldap_expan, add_memberof: true, add_web: true, sudo_ssh: true, ppolicy: true}
- { role: ldap_expan, add_memberof: true, add_web: true, sudo_ssh: true, ppolicy: true, crontab: true}
become: true
25 changes: 25 additions & 0 deletions roles/ldap_expan/files/slapcat_backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/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
16 changes: 16 additions & 0 deletions roles/ldap_expan/tasks/add_crontab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
# 增加定时备份管理
- name: 拷贝定时任务文件
copy:
src: slapcat_backup.sh
dest: /etc/openldap/slapcat_backup.sh
mode: 0755

- name: 为定时备份创建定时任务文件
cron:
name: ldap autobackup
minute: 0
hour: "*/6"
user: root
job: "/etc/openldap/slapcat_backup.sh"
cron_file: ansible_ldap-autobackup
6 changes: 5 additions & 1 deletion roles/ldap_expan/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@

- name: add ppolicy
include: add_ppolicy.yml
when: ppolicy
when: ppolicy

- name: add crontab
include: add_crontab.yml
when: crontab

0 comments on commit bfd2da1

Please sign in to comment.