iredmail - 手动删除用户的默认目录 - 批量删除邮件
需求:邮件塞满了磁盘的inodes。无需备份,直接强制删除所有用户的邮件。
尝试:
#!/bin/bash
# 先停止postfix
/usr/bin/systemctl stop postfix
# 导出用户名单到文件
doveadm user *@* > /run/mailtmp.txt
# 从文件每行读取用户名,再根据用户名得到用户默认存储目录,如 /var/vmail/vmail1/example.com/z/z/9/zz9976-2023.04.19.20.47.38/ ,最后删除相应的目录
cat /run/mailtmp.txt | while read LINE; do
su -s /bin/bash vmail -c "rm -rf `doveadm user -f home $LINE`"
done
/usr/bin/systemctl start postfix
参考:
- https://unix.stackexchange.com/questions/358740/this-user-is-currently-not-available-but-allow-to-run-script-by-this-user
- https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable
- https://wiki.dovecot.org/Tools/Doveadm/User
- https://serverfault.com/questions/580779/dovecot-remove-unused-inboxes
- https://docs.iredmail.org/backup.restore.html