| Line | |
|---|
| 1 | #!/bin/sh |
|---|
| 2 | # /etc/cron.daily/standard: standard daily maintenance script |
|---|
| 3 | # Written by Ian A. Murdock <imurdock@gnu.ai.mit.edu> |
|---|
| 4 | # Modified by Ian Jackson <ijackson@nyx.cs.du.edu> |
|---|
| 5 | # Modified by Steve Greenland <stevegr@debian.org> |
|---|
| 6 | # Modified by Simone Piccardi <piccardi@trelite.it> for LDAP backup |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | bak=/var/backups |
|---|
| 10 | LOCKFILE=/var/lock/cron.daily |
|---|
| 11 | umask 022 |
|---|
| 12 | |
|---|
| 13 | # |
|---|
| 14 | # Avoid running more than one at a time -- could happen if the |
|---|
| 15 | # checksecurity script lands on a network drive. |
|---|
| 16 | # |
|---|
| 17 | |
|---|
| 18 | if [ -x /usr/bin/lockfile-create ] ; then |
|---|
| 19 | lockfile-create $LOCKFILE |
|---|
| 20 | if [ $? -ne 0 ] ; then |
|---|
| 21 | cat <<EOF |
|---|
| 22 | |
|---|
| 23 | Unable to run /etc/cron.daily/back_ldap because lockfile $LOCKFILE |
|---|
| 24 | acquisition failed. This probably means that the previous days |
|---|
| 25 | instance is still running. Please check and correct if necessary. |
|---|
| 26 | |
|---|
| 27 | EOF |
|---|
| 28 | exit 1 |
|---|
| 29 | fi |
|---|
| 30 | |
|---|
| 31 | # Keep lockfile fresh |
|---|
| 32 | lockfile-touch $LOCKFILE & |
|---|
| 33 | LOCKTOUCHPID="$!" |
|---|
| 34 | fi |
|---|
| 35 | |
|---|
| 36 | # |
|---|
| 37 | # Backup LDAP database |
|---|
| 38 | # |
|---|
| 39 | |
|---|
| 40 | OLDBACK=slapd_back_`date +%F -d"8 days ago"` |
|---|
| 41 | if cd $bak ; then |
|---|
| 42 | # do the backup if the daemon is running |
|---|
| 43 | if [ -f /var/run/slapd/slapd.pid ]; then |
|---|
| 44 | /etc/init.d/slapd stop |
|---|
| 45 | # dump data with slapcat |
|---|
| 46 | slapcat > back_`date +%F` |
|---|
| 47 | # restart the daemon |
|---|
| 48 | /etc/init.d/slapd start |
|---|
| 49 | # remove old backups |
|---|
| 50 | [ -f "$OLDBACK" ] && rm back_`date +%F -d"8 days ago"` |
|---|
| 51 | # remove old log file |
|---|
| 52 | cd /var/lib/ldap |
|---|
| 53 | db4.2_archive -d |
|---|
| 54 | fi |
|---|
| 55 | fi |
|---|
| 56 | |
|---|
| 57 | # |
|---|
| 58 | # Clean up lockfile |
|---|
| 59 | # |
|---|
| 60 | if [ -x /usr/bin/lockfile-create ] ; then |
|---|
| 61 | kill $LOCKTOUCHPID |
|---|
| 62 | lockfile-remove $LOCKFILE |
|---|
| 63 | fi |
|---|