Plesk Backups

If you have a Plesk server or virtual server, I’m sure you have though about how to backup that server. If you haven’t, please think about it now. Once your server dies on you you’ll be so sorry that you will be slamming your head against the wall.

I’ve researched and tried several options to backup my Plesk server and I’d like to share them with you, hopefully saving you some work and headaches.

The Plesk backup tool

With Plesk’s own backup tool, you can backup and restore an entire Plesk panel. This is something which is important to me. If you just want to have a copy of the data in your sites and database, you might want to skip this and go directly to the rsync and rdiff-backup tools below.

The backup tool provided by Plesk is really unreliable. In Plesk 7.5, you have psadump. I once had to actually restore a site. I found out the database of that site was not present in the backup. The database usually is the most important part of a site so I was really annoyed. Plesk 8.0 now provides another backup tool which is incompatible with psadump. I’ve heard several webhosters with the same kinds of compaints: it’s still unreliable and incompatible with 7.5 backups. Outch.

If you want to use the psadump tool anyway, here’s the command I used to make a full backup:

ssh -f root@yourserver ‘/opt/psa/bin/psadump -f - –nostop –nostop-domain –do-not-dump-logs’ | split -b1000m - myserver_dump.`date +%F`.

This is for Debian / BSD servers. On Redhat servers, the tool is located at /usr/local/psa/bin/psadump so the command would be:

ssh -f root@yourserver ‘/usr/local/psa/bin/psadump -f - –nostop –nostop-domain –do-not-dump-logs’ | split -b1000m - myserver_dump.`date +%F`.

This command will login to your remove server and start psadump. The nostop options make sure that nothing is disabled while making the backup. do-not-dump-logs speaks for itself.. you don’t want to transfer gigabytes of logfiles so these are exluded from the backup.

4PSA Total Backup

Luckilly, the company 4PSA.com has stepped up and created a fantastic backup tool. 4PSA Total backup integrates with the Plesk control panel. You can schedule backups and store them at a remote server and local disk. The tool will let you make incremental backups, so you don’t have to upload multiple gigabytes of data on a daily basis. It uses tar but you may also choose to use the Plesk backup tool (not recommended!).
The only downside is that you have to pay for it. If you are a hoster or have a commercial site, the $99 is a small fee for the ease it offers you though.

Do-it-yourself

You can also backup your site data by using the usual unix tools. You have to know the important directories though. On Plesk, this is usually:

Site files:

  • /var/www/vhosts/ (on debian)
  • /home/httpd/vhosts/ (on red hat / centos)

Mysql databases:

  • /var/lib/mysql/

Those are the most important files. I wouldn’t recommend you trying to backup more (like DNS zones, etc.) because it will get complicated to make a full Plesk backup on your own.

So how do you make copies of those files? You can either use rsync or a tool called rdiff-backup. rsync will sync files with a remote place. It detects files that did not change and will skip those. This saves time and resources. rdiff-backup works in the same way but has an additional feature: incremental backups. With rdiff-backup, you can for example restore a file as it was 3 days ago. I personally think this is a bit overkill. I’m happy with just having an X days old backup, because I usually run a full backup once every week and not daily.
A typical rsync backup command looks like:

rsync -aze ssh root@remoteserver:/var/lib/mysql /backup/mysql

This will reserve file properties (-a) and it will compress data (-z). It will get the files from the external server “removeserver” (-e) by using ssh. Go here for some more examples. There are some improvements you can make. For example, using keys you can allow your server to login without a password so you can automate this with a small bash script run by the cron daemon.

The following command would be a typical usage of rdiff-backup:

rdiff-backup user@hostname.net::/remote-dir local-dir

There are much more examples here.

Related articles you might like:

5 Responses to “Plesk Backups” »»

  1. Comment by Nick | 06/02/07 at 11:23 pm

    Many thanks - very useful to know for a linux/plesk newbie like myself.

  2. Comment by Gilbert | 06/11/08 at 7:00 pm

    Good howto, BUT! don’t forget to omit the conf dir as different servers means different IP’s… and chroot dir. can also be excluded. –exclude */conf/* –exclude chroot/*.

    this applies when a plesk migration manager has been used prior to rsync.

    HTH

  3. Comment by Corey | 08/06/08 at 10:10 pm

    Um, rather than backing up live MySQL files that are susceptible to corruption, I do mysqldump against every database on a given hosting server. Something like so:

    find /var/lib/mysql -type d | sed -e ’s/\/var\/lib\/mysql\///’ | \
    grep -v “/var/lib/mysql” | \
    xargs -i \
    mysqldump -u admin –password=`cat /etc/psa/.psa.shadow` -r /var/dump/mysql/{}.sql {}

    Basically I created /var/dump/mysql and each night, prior to my rdiff-backup job, I overwrite the SQL dump files. rdiff-backup then keeps up to 7 versions of the file until they are pruned due to age.

    Not only does that protect you from corrupt database files, it also saves you if site A needs to do a restore but site B is ok, etc.

  4. Comment by erik | 08/07/08 at 9:03 am

    Hi Corey, actually I do the same as you these days. I make full database dumps and then run rdiff-backup over the entire server. It’s great to be able to restore a database or a file from x days ago.

  5. Comment by Alexander Driantsov | 09/02/08 at 2:09 pm

    I have hardcoded the script like this, for our hosting(it’s working perfectly, sending very good with load average and time taken for each user’s webroot backup):

    —————- CUT —————–
    #!/bin/sh
    # Incremental hosting backup script using rdiff
    # Author: Driantsov Alexander
    ####

    BACKUP_ADMIN_EMAIL=”my-email@my-host.com”
    BACKUP_MAIL_SUBJECT=”`hostname`: Backup Synchronization Result”
    BACKUP_LOG=”/var/log/backup-log”

    BACKUP_DELAY=”10″ # Delay between clients backup(seconds)
    BACKUP_PRIO=”20″ # Priority for the MySQL dump and rdiff-backup Min: 20 Max: -20
    BACKUP_DIFF_DIR=”/var/backup/hosting” # Diffs of dumps will be stored there
    BACKUP_TTL=”6M” # Time To Live

    SYNC_PRIO=”20″
    SYNC_SRV=”254.254.254.254″ # Remote server for backup storage
    SYNC_USER=”backup-user” # User at remote storage
    SYNC_SPEED=”200″ # Limit Synchronization Bandwidth to this number of KB/s
    SYNC_DIR=”/backup/hosting” #Directory on Remote server to synchronize backups in

    EXCLUDE_ARRAY=”**templates_c
    **html_cache”
    TMP_DIR=”/tmp”

    echo -en “$EXCLUDE_ARRAY\n”|while read exlude_dir; do exclude_str=`echo -en “${exclude_str}–exclude ${exlude_dir} “`; echo $exclude_str > $TMP_DIR/exclude_str.tmp ; done
    EXCLUDE_STR=`cat $TMP_DIR/exclude_str.tmp`
    rm $TMP_DIR/exclude_str.tmp

    backup_start=”$(date +%s)”
    load_average=`uptime|awk ‘{print $10″ “$11″ “$12}’`
    echo “Load overage at start: $load_average” > $BACKUP_LOG
    echo “BackingUP WebRoots:” >> $BACKUP_LOG
    mysql -uadmin -p`cat /etc/psa/.psa.shadow` -Bse “select login,home from sys_users;” psa| while read user path; do
    before_backup=”$(date +%s)”
    BACKUP_RESULT=`nice -n $BACKUP_PRIO rdiff-backup $EXCLUDE_STR $path/httpdocs $BACKUP_DIFF_DIR/$HOSTNAME/$user 2>&1`
    after_backup=”$(date +%s)”
    elapsed_seconds=”$(expr $after_backup - $before_backup)”
    load_average=`uptime|awk ‘{print $10}’|sed -e ’s/,//’`
    if [ -n “$BACKUP_RESULT” ]; then
    echo -en “$load_average - $elapsed_seconds secs - $user - ERRS: $BACKUP_RESULT” >> $BACKUP_LOG;
    else
    echo “$load_average - $elapsed_seconds secs - $user” >> $BACKUP_LOG;
    fi
    load_average=`uptime|awk ‘{print $10″ “$11″ “$12}’`
    sleep $BACKUP_DELAY;
    done

    backup_end=”$(date +%s)”
    backup_elapsed_seconds=”$(expr $backup_end - $backup_start)”

    echo “\nLoad overage after WebRoots backup: $load_average\n” >> $BACKUP_LOG
    #echo “Time taken for backup: $elapsed_seconds seconds” >> $BACKUP_LOG

    #Synchronization
    sync_start=”$(date +%s)”
    data_result=`nice -n $BACKUP_PRIO rsync -avz –bwlimit $SYNC_SPEED $BACKUP_DIFF_DIR/$HOSTNAME $SYNC_USER@$SYNC_SRV:$SYNC_DIR/$HOSTNAME|tail -n 2 2>&1`
    sync_end=”$(date +%s)”
    sync_elapsed_seconds=”$(expr $sync_end - $sync_start)”
    free_space_info=`nice -n $BACKUP_PRIO ssh $SYNC_USER@$SYNC_SRV df -h –sync -t ext3 2>&1`

    echo -en “Time taken for backup: $backup_elapsed_seconds seconds\nTime taken for synchronization: $sync_elapsed_seconds seconds\nWebRoot backup synchronization:\n $data_result \n\nInformation on free space on remote backup server: \n $free_space_info \n\n Backup Log: \n\n`cat $BACKUP_LOG`”| mail -s “$BACKUP_MAIL_SUBJECT” $BACKUP_ADMIN_EMAIL
    —————- CUT —————–

    Additionally we have such script for MySQL backups, these scripts works perfectly with load average <= 1. Good luck in codind and fighting with overheads caused by backups, I spent a days to findout the best way of MySQL backup, trying mysqldump, mysqlhotcopy and other methods :)

Leave a Reply »»