Q: How can you recover an email box and all its stored emails from a cPanel backup? A: You can recover an email box from a cPanel full backup extracting and copying the email files. Let’s see how to find out where are our emails stored inside a cPanel full backup, and how to copy that to your real email box to recover all your emails.
Recover an email box from a cPanel full backup step by step
Backups are very important in every web hosting server, and cPanel software includes a fantastic and useful way to backup all your website files, email boxes, databases, ssl certificates and dns zone information.
System backups are usually stored at this location:
/backup/
Those are the cpanel system backups created automatically by cPanel Backup Configuration settings at WHM.
The other type of cPanel backups that are useful to restore information are those called ‘full backups‘, this are the ones generated from the cPanel control panel, or from the console by using the /scripts/pkgacct command.
If you have any of this two types of backup, then it’s your lucky day, this are the perfect ones to recover an email box from on cPanel systems.
Emails are usually stored in this location:
/home/user/mail/domain.net/emailbox/
- user must be replaced with the real cpanel user.
- domain.net must be replaced with your real domain name.
- emailbox must be replaced with your email box name.
If you have a missing email account and you need to restore its contents the best way to do it is creating the email box from scratch, that means, move to cPanel – Email accounts and create the new email box.
Now that you have your email box created, let’s copy the files back to the original path from the weekly backup.
cp cpmove-user.tar.gz /root/temp mkdir /root/temp && cd /root/temp tar -xvpzf cpmove-user.tar.gz
or if it’s a cPanel system backup do the same and change the file name:
tar -xvpzf user.tar.gz
This will extract the files.
rsync -avpr user/homedir/mail/domain.net/emailbox/* /home/user/mail/domain.net/emailbox/
That will do the trick to recover all your emails.
Further reading:
- If you need to know more on how cPanel manual migrations work, please refer to the following docs: cP Manual Migrations
Also worth mentioning than there’s script which allows to restore mail only:
https://documentation.cpanel.net/display/ALD/Backup+Restoration#BackupRestoration-RestorationQueueScript
You can also extract directly from archive without the need to extract the whole archive if you’re short on space.
Thanks for pointing that out Ivan, I’m sure this is gonna help other users as well.