Backups

How to Back Up and Restore a cPanel Account Over SSH (pkgacct and restorepkg)

Short answer: As root, run /scripts/pkgacct USERNAME /backup to package one cPanel account (files, databases, email and settings) into /backup/cpmove-USERNAME.tar.gz. Copy the file off the server. To restore it on the same or another cPanel server, put the file in /home and run /scripts/restorepkg /home/cpmove-USERNAME.tar.gz. Restoring over an existing account replaces its data, so test first.

When to use pkgacct

  • Taking a quick, complete copy of one account before a risky change.
  • Moving a single account to another cPanel server when the Transfer Tool cannot connect.
  • Keeping an extra off-site copy of an important account.

For regular backups of every account, use WHM’s Backup Configuration instead, which runs on a schedule and can send backups off the server. See our automatic cPanel backups guide.

What the backup contains

Included Details
Home directory Website files, uploads and other files in /home/USERNAME
Databases MySQL or MariaDB databases and users owned by the account
Email Mail accounts, mailboxes, forwarders and filters
DNS zones Zones for the account’s domains
Settings Domains, subdomains, SSL certificates, cron jobs, FTP accounts and the hosting package

Step 1: check the disk space

The archive is roughly the size of the account, minus compression. Check the account size and the free space where you will store the file:

du -sh /home/USERNAME
df -h /backup

Step 2: create the backup

mkdir -p /backup
chmod 700 /backup

# Package the account into /backup
/scripts/pkgacct USERNAME /backup

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

Run it inside screen for large accounts. Store the archive in a folder that only root can read, never in the account’s own home folder: the archive contains the account’s databases and mail, and it would also be included in the next backup of that account. Run /scripts/pkgacct --help to see the options your cPanel version supports, such as skipping the home directory.

Step 3: copy the backup off the server

# From the server to backup storage
rsync -avP /backup/cpmove-USERNAME.tar.gz backupuser@backup.example.com:/backups/

# Or download it to your computer
scp root@your-server-ip:/backup/cpmove-USERNAME.tar.gz .

Delete the local copy from the server when you no longer need it there, so it does not fill the disk.

Step 4: restore the account

Upload the archive to /home on the server where you want to restore it, then run:

/scripts/restorepkg /home/cpmove-USERNAME.tar.gz

If an account with the same name already exists, the restore stops. To replace it, you must use the force option, which overwrites the existing account’s data. Take a fresh backup of that account first.

/scripts/restorepkg --force /home/cpmove-USERNAME.tar.gz

Step 5: check the restored account

  • ✓ The account appears in WHM under List Accounts with the right package and IP address.
  • ✓ The website loads. Test it with the hosts file before you change DNS. See our hosts file guide.
  • ✓ Databases connect, and email accounts can log in.
  • ✓ AutoSSL issues certificates once DNS points to the new server.

Restore from WHM instead

WHM has graphical tools that do the same work and show each step:

  • Backup > Backup Restoration restores accounts from the server’s scheduled backups.
  • Transfers > Restore a Full Backup/cpmove File restores a pkgacct archive you uploaded.
  • Transfers > Transfer Tool copies accounts directly from another server.

Back up as a cPanel user (without root)

Account owners without root access can download a full backup from cPanel: Files > Backup, then Download a Full Account Backup. The file is created in the home folder; download it and delete it from the server afterwards. Only the server administrator can restore a full backup.

Troubleshooting

Problem Likely cause Fix
pkgacct stops with a disk space error Not enough free space at the destination Free space, or write the backup to another disk.
restorepkg says the account exists An account with that user name is already on the server Remove it, or use –force after taking a backup of it.
Restored site shows database errors Database user or password differs in the site’s configuration Check the database name, user and password in the site’s config file.
Domain conflict during restore The domain already exists on another account Remove the domain from the other account first.

Need help with this?

Want backups that run and get tested without you thinking about it? Ask about our backup and server management services.

See server management plansContact @CustomerPanel

Frequently asked questions

Where does pkgacct save the backup?

In /home by default, as cpmove-USERNAME.tar.gz. Give a folder as the second argument to save it elsewhere.

Can I restore a pkgacct backup on another server?

Yes. Copy the archive to /home on the new cPanel server and run /scripts/restorepkg with the file path.

Does pkgacct include email and databases?

Yes. It packages files, databases, email, DNS zones and account settings.

Is it safe to keep backups in the user’s home folder?

No. Keep them in a root-only folder or off the server, because the archive contains databases and email.

Can a cPanel user restore a full backup?

No. Users can download full backups and restore partial ones, but a full restore needs the server administrator.


Sources