|
123456789101112131415161718192021222324252627 |
- #!/bin/bash
-
- # Variables
- MAIL_ROOT="/var/mail"
- BACKUP_ROOT_MAIL="/backup/mail"
- BACKUP_MAIL_RETENTION=31
-
- # Starting mail backup
- echo "Starting mail backup process ..."
-
- # Create directories if not exists
- mkdir -p ${BACKUP_ROOT_MAIL}
- HOUR=`date +%Y%m%d%H%M`
-
- # Create archive
- for domain in `ls ${MAIL_ROOT}`;
- do
- mkdir -p ${BACKUP_ROOT_MAIL}/${domain}
- for account in `ls ${MAIL_ROOT}/${domain}`;
- do
- tar czf ${BACKUP_ROOT_MAIL}/${domain}/${account}\_${HOUR}.tar.gz ${MAIL_ROOT}/${domain}/${account}
- done
- done
-
- # Purge old backup
- echo "Starting mail purge process for backup older than ${BACKUP_MAIL_RETENTION} ..."
- find ${BACKUP_ROOT_MAIL} -type f -mtime +${BACKUP_MAIL_RETENTION} -exec rm -f {} \;
|