server-tools !?!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
705 B

  1. #!/bin/bash
  2. # Variables
  3. MAIL_ROOT="/var/mail"
  4. BACKUP_ROOT_MAIL="/backup/mail"
  5. BACKUP_MAIL_RETENTION=31
  6. # Starting mail backup
  7. echo "Starting mail backup process ..."
  8. # Create directories if not exists
  9. mkdir -p ${BACKUP_ROOT_MAIL}
  10. HOUR=`date +%Y%m%d%H%M`
  11. # Create archive
  12. for domain in `ls ${MAIL_ROOT}`;
  13. do
  14. mkdir -p ${BACKUP_ROOT_MAIL}/${domain}
  15. for account in `ls ${MAIL_ROOT}/${domain}`;
  16. do
  17. tar czf ${BACKUP_ROOT_MAIL}/${domain}/${account}\_${HOUR}.tar.gz ${MAIL_ROOT}/${domain}/${account}
  18. done
  19. done
  20. # Purge old backup
  21. echo "Starting mail purge process for backup older than ${BACKUP_MAIL_RETENTION} ..."
  22. find ${BACKUP_ROOT_MAIL} -type f -mtime +${BACKUP_MAIL_RETENTION} -exec rm -f {} \;