File & Folder Restoration

Recover deleted files from backups, restore databases, and implement the 3-2-1 backup strategy to prevent future data loss.

When Files Go Missing

Files can disappear for many reasons: accidental deletion, a botched update, a hacked site, or a failed migration. The key is having backups — and knowing how to restore from them quickly.

cPanel File Manager Restoration

Check the Trash

cPanel's File Manager has a trash feature. Check File Manager → View Trash to see if deleted files can be recovered directly.

Use cPanel Backup Wizard

Go to cPanel → Backup Wizard → Restore. You can restore:

  • Home Directory — all files in your account
  • MySQL Databases — individual database backups
  • Email Forwarders & Filters

JetBackup / R1Soft

Many hosts install JetBackup or R1Soft for granular restores. In cPanel, look for JetBackup in the sidebar. You can browse backup snapshots by date, navigate the file tree, and restore individual files or directories without restoring the entire account.

Command-Line Restoration

Restoring from tar/gzip Backups

# List contents of a backup without extracting
tar -tzf backup-2024-01-15.tar.gz

# Extract entire backup
tar -xzf backup-2024-01-15.tar.gz

# Extract a single file from the backup
tar -xzf backup-2024-01-15.tar.gz path/to/specific/file.php

# Extract to a specific directory
tar -xzf backup-2024-01-15.tar.gz -C /home/user/restored/

Using rsync for Restoration

# Restore from a backup directory to the live site
rsync -avz /backups/2024-01-15/public_html/ /home/user/public_html/

# Dry run first (shows what would change)
rsync -avzn /backups/2024-01-15/public_html/ /home/user/public_html/

# Restore from a remote backup server
rsync -avz backup-server:/backups/latest/public_html/ /home/user/public_html/

Restoring from Git

If your site is version-controlled, git makes restoration straightforward:

# See what was changed/deleted recently
git log --diff-filter=D --summary

# Restore a specific deleted file
git checkout HEAD~1 -- path/to/deleted/file.php

# Restore a file from a specific commit
git checkout abc1234 -- path/to/file.php

# Restore the entire project to a previous state
git checkout abc1234 -- .

# If you just want to see the old version without restoring
git show abc1234:path/to/file.php

Database Restoration

mysqldump Backup & Restore

# Create a database backup
mysqldump -u username -p database_name > backup.sql

# Backup with compression
mysqldump -u username -p database_name | gzip > backup.sql.gz

# Restore from a backup
mysql -u username -p database_name < backup.sql

# Restore from compressed backup
gunzip < backup.sql.gz | mysql -u username -p database_name

phpMyAdmin Restore

  1. Log in to phpMyAdmin
  2. Select the target database
  3. Click the Import tab
  4. Choose your .sql backup file
  5. Click Go to import
Important

Always backup the current database before restoring an older version. Restoring overwrites existing data. Create a snapshot of the current state first so you can roll back if needed.

The 3-2-1 Backup Rule

The gold standard for data protection:

  • 3 copies of your data (the original + 2 backups)
  • 2 different storage types (e.g., local disk + cloud storage)
  • 1 offsite backup (in case of physical disaster)

Automated Backup Script

#!/bin/bash
# backup.sh — Run via cron: 0 2 * * * /home/user/scripts/backup.sh

DATE=$(date +%Y-%m-%d)
BACKUP_DIR="/home/user/backups/$DATE"
mkdir -p "$BACKUP_DIR"

# Backup files
tar -czf "$BACKUP_DIR/files.tar.gz" /home/user/public_html/

# Backup database
mysqldump -u db_user -p'db_pass' db_name | gzip > "$BACKUP_DIR/database.sql.gz"

# Remove backups older than 30 days
find /home/user/backups/ -type d -mtime +30 -exec rm -rf {} +

echo "Backup completed: $BACKUP_DIR"
Pro Tip

Test your backups regularly by restoring them to a staging environment. A backup you can't restore from is worthless. Schedule a monthly "restore drill" to verify your backup integrity.