How to Generate and Restore a Full cPanel Account Backup Using CLI

  Uncategorized

Introduction

Creating and restoring backups of cPanel accounts is an important task for server administrators. It helps protect website files, databases, emails, DNS records, and account configurations.

In cPanel/WHM servers, we can use command-line tools like pkgacct to generate a full account backup and restorepkg to restore the account from the backup file. This method is useful when handling migrations, disaster recovery, or manual account backups.


Prerequisites

Before starting the backup and restore process, make sure the following requirements are met:


Backup Generation Steps

Step 1: Connect to the Server via SSH

Log in to the server using SSH as the root user.

ssh root@SERVER_IP_ADDRESS

Replace SERVER_IP_ADDRESS with the actual server IP address.


Step 2: Go to the cPanel Scripts Directory

Navigate to the cPanel scripts directory.

cd /scripts

Alternatively, you can use:

cd /usr/local/cpanel/scripts

Step 3: Generate the cPanel Account Backup

Use the pkgacct command to create a full backup of the cPanel account.

./pkgacct ACCOUNT_USERNAME DESTINATION_PATH

Example:

./pkgacct exampleuser /backup

This command will generate a full backup of the exampleuser cPanel account and store it in the /backup directory.


Step 4: Monitor the Backup Process

The backup process may take some time depending on the account size. You can monitor the progress directly in the terminal.

Once completed, the backup file will be created in the destination path with a name similar to:

cpmove-ACCOUNT_USERNAME.tar.gz

Example:

cpmove-exampleuser.tar.gz

Step 5: Verify the Backup File

After the backup is completed, verify that the backup file exists.

ls -lh /backup/cpmove-ACCOUNT_USERNAME.tar.gz

Example:

ls -lh /backup/cpmove-exampleuser.tar.gz

Restoration Steps

Step 1: Connect to the Destination Server via SSH

Log in to the server where the cPanel account needs to be restored.

ssh root@SERVER_IP_ADDRESS

Step 2: Move the Backup File to the Correct Location

Place the backup file in one of the supported locations, such as:

/home
/root
/usr/local/cpanel
/backup

Example:

mv cpmove-exampleuser.tar.gz /home/

Step 3: Go to the cPanel Scripts Directory

Navigate to the cPanel scripts directory.

cd /scripts

Or:

cd /usr/local/cpanel/scripts

Step 4: Restore the cPanel Account

Use the restorepkg command to restore the full cPanel account.

./restorepkg BACKUP_FILENAME

Example:

./restorepkg /home/cpmove-exampleuser.tar.gz

You can also restore using only the username if the backup file is already in a supported location:

./restorepkg exampleuser

Step 5: Monitor the Restoration Process

The restore process will display progress in the terminal. It will restore the account files, databases, email accounts, DNS records, and other cPanel configurations.


Step 6: Verify the Restored Account

After the restoration is completed, verify the account from WHM.

Check the following:


Useful Commands

To check available disk space:

df -h

To check backup file size:

ls -lh /backup/

To generate backup using full path:

/usr/local/cpanel/scripts/pkgacct ACCOUNT_USERNAME /backup

To restore backup using full path:

/usr/local/cpanel/scripts/restorepkg /home/cpmove-ACCOUNT_USERNAME.tar.gz

Conclusion

Generating and restoring full cPanel account backups through the command line is a reliable method for server migration, disaster recovery, and manual backup management.

Using pkgacct, we can create a complete backup of a cPanel account, including website files, databases, emails, and configurations. Using restorepkg, we can restore the account safely on the same or another cPanel server.

It is recommended to verify the backup file after generation and carefully test the restored account to ensure all services are working properly.

LEAVE A COMMENT