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:

3-Mustermann-db_test.sql.gz.gpg

3-mails-mustermann.de-erwin@mustermann.de.tar.gz.gpg

3-mustermann.de.tar.gz.gpg
The leading 3 is the backup number. I have always 5 backups and they are automatically overwritten.
#!/bin/bash
# Daycount (for 5 Backups)
DOW1=`date +%j`
DOW=`expr $DOW1 % 5`
# Databases
DBISPconfig="dbispconfig"
# Binaries
SQLDUMP="/usr/bin/mysqldump"
SQLBIN="/usr/bin/mysql"
GPG="/usr/bin/gpg"
# tar-Options
BACKUP_TAR_OPT_NOZIP="-ch"
# 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
BACKUP_NO=$LEVEL

# User DB
$SQLBIN $DBISPconfig -e "select database_name from web_database
order by database_id asc;" | grep -v 'database_name' |
while read DBNAME
do
  $SQLBIN $DBISPconfig -e "SELECT
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
  do
    $SQLDUMP $DBNAME | $GPG_OPTIONS > $BPATH/$DOW-$FILENAME.sql.gpg
    ncftpput ${BACKUP_FTP_OPT} ./user/databases $BPATH/$DOW-$FILENAME.sql.gpg
    done
done

# 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
  do
    $SQLBIN $DBISPconfig -e "SELECT email AS EMAIL, maildir AS MAILDIR FROM mail_user WHERE email LIKE '%$MAILDOMAIN';" |
    grep -v 'MAILDIR' |while read t
    do
      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
    done
  done

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

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


Leave a Reply to Florian Schaal Cancel reply

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

2 thoughts on “ISPConfig – Backup per Client

  • Mirco

    Hallo,
    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 3.0.5.4 geben.