Skip to content

Restoring only files from a cPanel backup — not the whole account

How to recover specific files or a directory from a cPanel backup without overwriting the entire account — using the cpmove archive, the home-directory tree inside it, and what a full restore would have clobbered.

The most common restore is also the one cPanel’s full-restore button handles badly: someone deleted or broke a few files and wants those back — not the databases, not the mail, not the email accounts as they were last night. Running a full account restore to recover one directory overwrites everything else with the backup’s version, undoing every change made since. The right move is to reach into the backup archive, pull out just the files you need, and copy them into place — leaving the rest of the live account untouched.

What’s happening

A cPanel backup of an account is a cpmove/account archive: a .tar.gz (or a JetBackup snapshot) containing the whole account — the homedir tree (the user’s files, public_html, mail), database dumps, DNS zones, and the metadata cPanel needs to recreate the account. WHM’s Restore a Full Account Backup (and the Backup Restoration / Transfer Tool restore) replays all of that, overwriting the live account’s files, databases, and settings with the archive’s. That is correct for rebuilding a lost account, and wrong for recovering a few files — it throws away everything that changed after the backup was taken.

To restore only files, you do not run a restore at all. You extract the archive (or browse the snapshot) to a staging location, locate the files inside the archive’s homedir/ tree, and copy just those into the live account — then fix ownership so the cPanel user owns them. The archive’s internal layout mirrors the account: a backup of user acme has the files under a homedir/ directory, with public_html/, mail/, and the rest beneath it. JetBackup makes this easier with a File Manager / file-level restore that lets you pick individual files or folders from a snapshot without unpacking anything. Either way, the discipline is the same: stage, pick, copy in, fix ownership, verify — never replay the whole archive to get a subset.

How to verify

Find the backups that exist for the account and pick the date that predates the loss:

# cPanel local backups by bucket and date
ls -la /backup/daily /backup/weekly /backup/monthly 2>/dev/null | grep <cpaneluser>
ls -la /backup/*/accounts/ 2>/dev/null | grep <cpaneluser>

# JetBackup snapshots for the account, if JetBackup is installed
jetbackup5api -F listBackupsForAccount -D "account=<cpaneluser>" 2>/dev/null

Look inside the archive without extracting the whole thing, to confirm the file is in there:

# List the archive's contents and find the file's path inside homedir/
tar tzf /backup/daily/<cpaneluser>.tar.gz | grep 'public_html/wp-config.php'
tar tzf /backup/daily/<cpaneluser>.tar.gz | grep 'homedir/' | head -20

Confirm the current (broken) file and what it should be replaced with:

# The live file's current state and ownership
ls -la /home/<cpaneluser>/public_html/wp-config.php
stat /home/<cpaneluser>/public_html/wp-config.php

The fix / steps

  1. Pick the backup from before the loss, not the newest. Identify the most recent backup taken before the files were deleted or corrupted. The newest daily may already contain the broken state. Confirm the date against when the problem started — restoring from after the incident just recovers the damage.
  2. Stage the archive somewhere safe — never extract over the account. Extract to a scratch directory outside the account, so nothing touches the live files yet. For a tar archive, pull only the path you need rather than unpacking the whole thing: tar xzf /backup/daily/<cpaneluser>.tar.gz -C /root/restore_stage <cpaneluser>/homedir/public_html/wp-config.php. Staging keeps the live account intact while you work.
  3. Use JetBackup’s file-level restore if it is installed. If the server runs JetBackup, skip manual extraction: open the snapshot’s File Manager in JetBackup, browse to the file or folder, and restore just that. JetBackup handles the extraction and places it back, which is faster and less error-prone than unpacking a tarball by hand. Pick file-level, not the full-account restore.
  4. Copy only the needed files into the live account. From the staging directory, copy the specific files or directory into place over the broken ones (cp -a /root/restore_stage/<cpaneluser>/homedir/public_html/wp-config.php /home/<cpaneluser>/public_html/). Copy a whole directory only if that whole directory is what was lost. Never cp the entire homedir/ — that is a full restore by another name and clobbers everything newer.
  5. Fix ownership and permissions to the cPanel user. Files copied as root are owned by root and the site cannot read or write them. Set ownership back: chown -R <cpaneluser>:<cpaneluser> /home/<cpaneluser>/public_html/wp-config.php (and the directory if you restored one). Confirm permissions match what the application expects — a restored file owned by root is a common cause of “it still does not work” after a file restore.
  6. Leave databases and mail alone unless they were the loss. A file-only restore should not touch MySQL or the Maildir. If the lost data was in a database, restore that database from its dump inside the archive (mysql dbname < backup.sql) as a separate, deliberate step — do not run a full account restore to recover one table. Keeping each restore scoped to exactly what was lost is the whole point.
  7. Verify the recovered files work in context. Load the site (or the affected feature) and confirm the restored file behaves — a config file that connects, an image that displays, a script that runs. Check ownership one more time. The restore is successful when the specific thing that broke now works, with everything else on the live account unchanged from before you started.
  8. Clean up the staging directory. Remove the extracted archive from the scratch location once the restore is verified (rm -rf /root/restore_stage/<cpaneluser>). A staged copy of an account’s files left under /root is both clutter and a small data-exposure risk. Confirm the live account is correct first, then delete the staging copy.

A file restore is done when exactly the lost files are back, owned by the cPanel user, with the rest of the account untouched by the recovery. Stack Harbor performs scoped cPanel file and data restores under managed cPanel operations — start a conversation when you need a few files back without a full restore.