How to Backup and Restore cPanel Accounts via SSH
Backing up and restoring cPanel accounts via SSH is a critical skill for any server administrator. This guide covers how to create individual account backups and restore them using the command line.
How to Create a Backup of an Individual cPanel Account via SSH
- Log in to the SSH as the root user.
- Enter the following command:
/scripts/pkgacct username
Note: The account backup will be created in the current directory you are in. The backup file will be named cpmove-username.tar.gz.
Backup to a Specific Directory
To save the backup to a specific location:
/scripts/pkgacct username /path/to/backup/directory
How to Restore an Individual cPanel Account via SSH
- Navigate to the directory where the backup file is stored.
- Enter the following command:
/scripts/restorepkg username
Note: You must be in the directory where the cpmove-username.tar.gz file is located, or specify the full path.
Restore from a Specific Path
/scripts/restorepkg /path/to/backup/cpmove-username.tar.gz
Backup All cPanel Accounts
To create backups for every cPanel account on the server:
for user in $(ls /var/cpanel/users); do /scripts/pkgacct $user /backup/; done
Useful Options
--skiphomedir— Skip the home directory (backs up only MySQL, email, and configs).--skipmysql— Skip MySQL databases.--skipacctdb— Skip the account database backup.
Troubleshooting Common Issues
- Disk space error: Make sure you have enough free disk space in the target backup directory.
- Permission denied: Ensure you are running the commands as root.
- Account already exists: If restoring an account that already exists, use
--forceflag to overwrite.