Skip to content
Alex Kovalev

cPanel & WHM CLI: Back Up, Move, and Restore an Account

A practical cPanel and WHM command-line guide for creating cpmove backups, moving accounts between servers, restoring them safely, and checking what went wrong.

Guide4min read
Server rack with network cables in a data center
Server rack with network cables in a data center

You need to move a cPanel account, restore a broken one, or make a backup before touching something scary. The CLI is faster than clicking through WHM. It is also very good at doing exactly what you told it to do.

This guide covers the commands I use most: pkgacct, restorepkg, scp, and whmapi1.

Two paths to keep in your head: the scripts live in /usr/local/cpanel/scripts, and account files usually live in /home/USERNAME.

The short version

Create a full account archive:

Terminal window
/usr/local/cpanel/scripts/pkgacct USERNAME /home

This creates /home/cpmove-USERNAME.tar.gz.

Copy it to another server (you will need SSH access):

Terminal window
scp /home/cpmove-USERNAME.tar.gz root@NEW_SERVER:/home/

Restore it there:

Terminal window
/usr/local/cpanel/scripts/restorepkg /home/cpmove-USERNAME.tar.gz

Run these as root. They change server-level cPanel config, not just files in someone’s home directory.

What is a cpmove archive?

pkgacct creates a portable cpmove archive. It contains the account’s files, databases, mail, DNS data, SSL data, cron jobs, and cPanel settings.

You normally do not need to unpack it. cPanel knows the format already. That is one less tarball archaeology project.

Back up one cPanel account

That’s the pkgacct line from the short version. Keep the explicit /home at the end: it makes the archive easy to find.

To inspect it without extracting it:

Terminal window
tar -tzf /home/cpmove-USERNAME.tar.gz | less

To compare the file after copying it, make a checksum on both servers:

Terminal window
sha256sum /home/cpmove-USERNAME.tar.gz
Compare hashes

STOP. Mystery archive.1 character out of 64 is different. That is enough.

Nothing leaves your browser. It is string comparison, not magic.

The two hashes should match. If they do not, stop there. Do not restore a mystery archive.

Restore a cPanel backup

restorepkg accepts either a full path to an archive, like in the short version, or a username. The full path is clearer. Restoring by username works when the archive is in one of cPanel’s search paths, such as /home:

Terminal window
/usr/local/cpanel/scripts/restorepkg USERNAME

Restoring an existing account

Be careful here. If the account already exists, --force behaves much like --skipaccount: it restores what it can while leaving existing data on the server.

Terminal window
/usr/local/cpanel/scripts/restorepkg --force /home/cpmove-USERNAME.tar.gz

That can leave a confusing mix of old and restored data. If you need a clean replacement, take a fresh backup, plan the downtime, and test the restore on a staging server first.

Restore under a different username

Use --newuser when the target username must change:

Terminal window
/usr/local/cpanel/scripts/restorepkg --newuser NEWUSER /home/cpmove-OLDUSER.tar.gz

The new name must not exist. It must be 16 characters or fewer, and its first eight characters must be unique on the server. Database users do not all get renamed automatically, so check the application configuration after the restore.

Where cPanel keeps account files

Most accounts live under /home, but a server can use other home partitions too. Do not assume every account lives in the same cupboard.

WhatTypical path
Account home/home/USERNAME/
Website root/home/USERNAME/public_html/
Mail/home/USERNAME/mail/
Account config/var/cpanel/users/USERNAME
DNS zones/var/named/
Apache logs/usr/local/apache/logs/

The cpuser file at /var/cpanel/users/USERNAME is the main account configuration file. Read it before editing it. Better yet, use WHM or a documented script where possible.

Useful WHM and cPanel commands

List accounts:

Terminal window
whmapi1 listaccts

Show one account:

Terminal window
whmapi1 accountsummary user=USERNAME

Want JSON instead of YAML?

Terminal window
whmapi1 --output=jsonpretty accountsummary user=USERNAME

On CloudLinux, use the full command path:

Terminal window
/usr/local/cpanel/bin/whmapi1 accountsummary user=USERNAME

Other useful scripts:

JobCommand
Create an account archive/usr/local/cpanel/scripts/pkgacct USERNAME /home
Restore an archive/usr/local/cpanel/scripts/restorepkg ARCHIVE
Remove an account/usr/local/cpanel/scripts/removeacct USERNAME
Rebuild Apache config/usr/local/cpanel/scripts/rebuildhttpdconf
Restart Apache/usr/local/cpanel/scripts/restartsrv_httpd
Update domain mappings/usr/local/cpanel/scripts/updateuserdomains

Use the full script path. cPanel recommends it, even if you are already in /usr/local/cpanel/scripts.

Remove an account

This deletes the account’s data. Make a backup first.

Terminal window
/usr/local/cpanel/scripts/removeacct USERNAME

The script asks for confirmation. --force skips that prompt. It does not make the command less destructive.

A quick recovery checklist

The command finishing is not the same thing as the migration finishing.

  1. Create a cpmove archive with pkgacct.
  2. Copy it to the destination.
  3. Compare the checksum on both servers.
  4. Restore it with restorepkg.
  5. Check the website and database connection. A crashed MySQL table looks like a broken site with no useful error.
  6. Check mail (SPF, DKIM and DMARC), DNS, SSL, and cron jobs.
  7. Keep the archive until you are happy with the result.

FAQ

Where does pkgacct save the backup?

If you pass /home as the final argument, it saves the archive there. Without a directory, cPanel uses the home directory with the most free space.

Can I restore a cpmove archive on another cPanel server?

Yes. That is what pkgacct archives are for. Make sure the target server has enough free disk space and a compatible cPanel setup.

Does a cpmove archive transfer two-factor authentication?

No. cPanel does not transfer an account’s 2FA configuration. The user must set it up again on the new server.

Should I extract the archive before restoring it?

Usually, no. Give the archive directly to restorepkg. Extract it only when you need to inspect a file or recover a small piece of data.

Sources

Comments

Comments live in GitHub Discussions (via giscus), so you need a GitHub account to join in.

I’ll chirp when there’s a new post

One email per new post, usually on a Friday. Nothing else, and you can unsubscribe anytime.

Prefer a feed reader? There’s an RSS feed.

© Alex Kovalev. All rights reserved. · Privacy Policy