Create a Simple Backup Script for Postfix
You need several different methods of backing up your mail server. One of those methods is using a compressed tar file of all of the important configuration files and directories that have content for Postfix. In addition, you will need to add a timestamp for your backups to you can go back and dig out mail from the archives if needed. The other advantage of a timestamp backup is that you will not overwrite previous backups.
Use vi or your favorite text editor and create this bash shell script. The first line tells indicates that it is a bash shell script. The lines that start with “#” are comments. The TIMSTAMP line provides a date, right down to the second so that you will always have backups with different dates. The script echos the TIMESTAMP so that it can be made available to the tar commands. The tar commands create a backup with an ending of “.tar.gz” which will compress the backup to save space. Note that the location for backup is listed and then the directory you want to backup is listed. There are two main directories that you will want to backup, /etc and /var. The /etc directory will contain the configuration for Postfix which is listed in /etc/postfix but also it will backup amavisd.conf, dovecot configuration, etc. The /var directory has the actual mail that is saved in /var/spool/vhosts, the virus file is /var/virusmails, /var/clamav has your anti-virus database and /var/log has log files that you will want to retain for evaluation. Please note that this backup could be large depending upon your mail traffic to take that into account if you automate it.
The example shows backing up to the /home directory but of course you will want to choose a partition that is on a separate drive from your mail server. You will also see a number of exclude options so that you do not back up .gz files or .rpm files as these will drastically alter the size of the backup.
# Timestamped Backup for Postfix
tar czvf /home/postfix_$TIMESTAMP.tar.gz /etc
tar czvf /home/var_$TIMESTAMP.tar.gz –exclude=’*.gz’ –exclude=’*.rpm’ /var