Question
How do I restore missing emails from a backup within the command line?
Answer
Note: In the following examples, "$username," "$emailusername," and "$domain.tld" must be replaced with the cPanel account's username, the email account's username, and the account's domain name, respectively.
- Log into the cPanel user's account.
- Ensure that the target email account exists.
- Access the server's command line as the
rootuser via SSH or Terminal in WHM. -
Create a staging directory.
# mkdir -vp /path/to/extraction/folder/
-
Extract the contents of the backup for the account.
# tar -xf /path/to/backup/location/$username.tar.gz -C /path/to/extraction/folder/
Note: The paths "/path/to/backup/location/" and "/path/to/extraction/folder/" must be replaced with the path to the backup location and the path to the extraction folder.
-
To copy all of the email account's files back to the email account's folder under the cPanel account.
# rsync -avP --ignore-existing --progress /path/to/extraction/folder/$username/homedir/mail/$domain.tld/$emailusername/cur /home/$username/mail/$domain.tld/$emailusername/cur
Note: If you wish to restore all emails, you must copy all the mail directories (cur, new, .spam, .Sent, .Trash, etc.).
-
Change the ownership of the mail files.
# find /home/$username/mail/$domain.tld/$emailusername/ ! -user $username -exec chown $username. {} \;
Additional Resources
How to manually extract individual files from a cPanel backup with the tar utility
Comments
0 comments
Article is closed for comments.