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

MIGRATION TIPS

If this backup/restore was to move a domain to a new server, here are some useful tips:

– Set the TTL for the zone to something low like 600 more than a day in advance.

– After the move, you can add something like this to the .htaccess file of the site on the old server (for web requests that still make it there):

RewriteEngine on
RewriteRule (.*) http://domain.com.previewhostname/$1 [P]

where domain.com.previewhostname would be where the site can be viewed before dns is changed.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: