Backup and restore a Plesk domain from the command line

BACKUP

Set a domain name as a variable in your shell (not really required, just makes the rest harder to screw up if you copy and paste from this howto):

DOMAIN_NAME=example.com

Go to the directory where plesk keeps the dumps

cd /var/lib/psa/dumps/$DOMAIN_NAME

Create a file with the description. even if you don’t care about the description, the file needs to exist.

echo "description goes here" > description.txt

Run the backup:

/usr/local/psa/admin/bin/domain_bu --backup --domain-name  $DOMAIN_NAME --dump-file $DOMAIN_NAME.domain_dump --desc-file  description.txt

Note that the shell prompt will be returned to you before the backup is completd. you can watch for the backup to be finished with this command (after waiting a moment or two for backup_restore.log to be created if it wasn’t there already):

tail -f backup_restore.log

When you see the text “Single domain backup is successfully completed.” (or something to that effect, depending on your version), the backup is completed.

RESTORE

To restore again with the backup, or restore on another server:

– Add the domain under the desired client in plesk (the domain has to exist in plesk to continue).

– Copy the .dump file to other server’s /var/lib/psa/dumps/[DOMAIN_NAME] directory.

– Set a domain name, client login and ip address the site should use as variables in your shell (not really required, just makes the rest harder to screw up if you copy and paste from this howto):

DOMAIN_NAME=example.com
CLIENT_LOGIN=myclient
IP_ADDRESS=1.2.3.4

Go to the dumps directory where you had copied the dump to

cd /var/lib/psa/dumps/$DOMAIN_NAME

Run the restore command:

/usr/local/psa/admin/bin/domain_bu --restore --domain-name  $DOMAIN_NAME --client-login $CLIENT_LOGIN --domain-ip $IP_ADDRESS  --dump-file $DOMAIN_NAME.domain_dump

If you get errors when restoring related to unmatched cert, see the instructions here: http://forum.plesk.com/showthread.php?s=&threadid=12274

Advertisements