I have an email server and I want to backup everything under /var/spool/mail/ and als the email boxes in the user homes.
Using tar when archiving the mail results in the following:
tar: var/spool/mail/server: file changed as we read it
tar: Error exit delayed from previous errors
Is there any better way to backup mail without temporary stopping the email server?
If your server uses LVM then you can create a snapshot of the filesystem containing the spool. You then can mount the snapshot somewhere and tar the directory on the snapshot. This wil ensure that the mail directory that you want to archive doesn't change anymore while the live server will continue to process mails.
This is a common problem. Common answer is to use tar nevertheless. Bigger boys use transactional filesystems which support snapshots and making backups of snapshots.
Another shot is to make a copy of the backup ( with hardlinks if possible ) and then use rsync to update the copy. This will minimize the transfers and lessens the damage.
tar is not designed for efficient and reliable error free backups. It is better to use some backup utility to accomplish this task. i would personally recommend bacula for this task, as through it, you can automate backups at any schedule. Set backups once, and forget.