ISPConfig – Backup per Client 2

If you backup the e-mails on a server in a complete archive and then want to extract only a single mailbox or even a few emails back, you will be happy if the archive has a only few MB.

The same applies for web domains or database (here is a global dump almost a disaster).

My backup script writes many quantity archives. Neither the term nor the amount of space needed are therefore larger. The restore is for it – and that is what matters most – much faster. I have not only unpack a huge archive and search through it.I just take the smaller archives from the backup space.

I want to backup

  1. the mysql-databases for each client
  2. each single mailbox
  3. each webspace

This results in various archives, for example:

The leading 3 is the backup number. I have always 5 backups and they are automatically overwritten.
# Daycount (for 5 Backups)
DOW1=`date +%j`
DOW=`expr $DOW1 % 5`
# Databases
# Binaries
# tar-Options
# gpg-Options
GPG_OPTIONS="gpg -e -r 8F1D5389"
# Level
LEVEL=`date +%u` # day of week (1..7); 1 is Monday
(( LEVEL-- )) # Mon full-Backup, Sun level 6

# User DB
$SQLBIN $DBISPconfig -e "select database_name from web_database
order by database_id asc;" | grep -v 'database_name' |
while read DBNAME
CONCAT(c.username,'_',w.database_name) AS FILENAME FROM client c,
web_database w WHERE w.sys_groupid = c.client_id+1 AND
w.database_name = '$DBNAME';" | grep -v 'FILENAME' |
  while read FILENAME
    ncftpput ${BACKUP_FTP_OPT} ./user/databases $BPATH/$DOW-$FILENAME.sql.gpg

# Client maildomains
$SQLBIN $DBISPconfig -e "SELECT domain AS MAILDOMAIN FROM mail_domain WHERE active='y' order by domain asc;" |
grep -v 'MAILDOMAIN' | while read MAILDOMAIN
    $SQLBIN $DBISPconfig -e "SELECT email AS EMAIL, maildir AS MAILDIR FROM mail_user WHERE email LIKE '%$MAILDOMAIN';" |
    grep -v 'MAILDIR' |while read t
      email=`echo $t|cut -d" " -f1`
      maildir=`echo $t|cut -d" " -f2`
      tar cfz - $maildir | $GPG_OPTIONS > $BPATH/$DOW-mails-$MAILDOMAIN-$email.tar.gz.gpg
      ncftpput ${BACKUP_FTP_OPT} ./user/maildomains/$MAILDOMAIN $BPATH/$DOW-mails-$MAILDOMAIN-$email.tar.gz.gpg

# Client websites
$SQLBIN $DBISPconfig -e "SELECT domain AS WEBSITE FROM web_domain WHERE active='y' AND type='vhost';" |
grep -v 'WEBSITE'
while read WEBSITE
  tar czf $BPATH/$DOW-website-$WEBSITE.tar.gz $WWW/$WEBSITE/*
  ncftpput ${BACKUP_FTP_OPT} ./user/webdomains $BPATH/$DOW-website-$WEBSITE.tar.gz

Ncftpput pushes the archives in the background in the backup space.

Leave a comment

Your email address will not be published. Required fields are marked *

2 thoughts on “ISPConfig – Backup per Client

  • Mirco

    vielen Dank für die interessante Anleitung.
    Wie genau läuft das mit dem .gpg, was muss man da beachten und wie richtet man das ein?

    LG, Mirco

    • Florian Schaal Post author

      Du kannst GPG auch weglassen. Ansonsten: The GNU Privacy Handbook

      ISPConfig kann aber mittlerweile Backups für Web und Datenbanken anlegen. Eine Backupfunktion für Emails habe ich in das devel-git integriert. Wenn ich etwas Zeit habe, wird es dazu noch einen Backport für die aktuelle Version geben.