Want to test new themes, tweak plugins, or experiment with design changes without worrying about breaking your live site? Working locally is the way to go! Having a local copy of your WordPress site means you can tinker to your heart’s content while your visitors keep enjoying a smooth experience.
Good news! If you’re hosting with DomainsFoundry’s WordPress Hosting, you’re already covered with automated daily off-server backups for disaster recovery. These backups keep your live site safe and can be easily restored through your DomainsFoundry Dashboard whenever you need them.
This guide will walk you through creating a complete exportable copy of your live WordPress site specifically for local development. The handy script we’ll set up lets you:
- Export your entire WordPress installation (files + database) in just minutes
- Choose between a FULL export (everything included) or SMALL export (faster, skips large media files)
- Download a single compressed file right from cPanel File Manager
- Import into your favorite local WordPress setup (XAMPP, Local by Flywheel, MAMP, you name it!)
- Test all your changes safely before pushing them live to your DomainsFoundry Managed WordPress Hosting site
The export gets tucked away in a secure, private folder and uses maximum compression to save space and speed up your download. Once you’ve got it, you’ll have everything you need to replicate your live site locally for development and testing.
What This Script Does
This automated script creates a complete snapshot of your WordPress site by:
- Grabbing database credentials from your wp-config.php file
- Exporting your WordPress database with all your content, posts, settings, users, and configurations
- Archiving your WordPress files (themes, plugins, uploads, core files, and any custom code)
- Giving you two export options: FULL (complete replica) or SMALL (skips wp-content/uploads for quicker downloads)
- Compressing everything into a single .tar.gz file using maximum compression
- Storing it securely in a private folder (_private_backups) that’s completely hidden from web browsers
After running the script, just download the export file through cPanel File Manager and extract it in your local WordPress setup. Your live site on DomainsFoundry’s hosting stays completely untouched throughout the whole process!
What You’ll Need
Before we get started, make sure you have:
- A WordPress website up and running on your DomainsFoundry hosting account
- A DomainsFoundry hosting plan with SSH access enabled (check your plan details to confirm SSH is available)
- Basic familiarity with SSH and command-line usage
- Access to cPanel or your hosting control panel
- Enough free disk space in your hosting account to store the backup files. As a rule of thumb, you’ll want at least the same amount of free space as your WordPress site and database combined.
Step 1: Create Your Private Backup Folder
Let’s keep your backup files safe and sound in a location that’s not publicly accessible. This way, nobody can stumble upon and download your backups directly.
- Log in to your cPanel account.
- Open File Manager.
- Head to your home directory (it’ll look something like
/home/username/). - Click + Folder and create a folder called
_private_backups.
Perfect! This folder will store your backup securely since it’s outside the public_html directory.
Step 2: Create Your Backup Script
- Open File Manager or connect to your hosting account using SSH.
- In your home directory, click + File and name it
wp_full_backup.sh. - Paste the following script into the file.
#!/bin/bash
# ============================================================================
# WordPress Site Export Script for Local Development
# ============================================================================
# This script creates a complete copy of your live WordPress site for local
# development. It packages both your WordPress files and database into a single
# compressed archive that you can download and import into your local environment.
#
# Perfect for: Local WordPress development, staging environments, testing changes
# before deploying to your live DomainsFoundry Managed WordPress Hosting site.
#
# What this script does:
# 1. Exports your WordPress database with all content, settings, and data
# 2. Archives your WordPress files (themes, plugins, uploads, core files)
# 3. Gives you two options: FULL export or SMALL export (excludes large uploads)
# 4. Creates a single compressed .tar.gz file you can download via cPanel
# 5. Stores the export in a private folder (_private_backups) for security
#
# After running this script, download the generated .tar.gz file from
# ~/private_backups/ and extract it in your local WordPress development setup.
# ============================================================================
# === Self-chmod to ensure script is executable ===
SCRIPT_PATH="${BASH_SOURCE[0]}"
if [[ -f "$SCRIPT_PATH" ]]; then
chmod 700 "$SCRIPT_PATH" 2>/dev/null
fi
# === CONFIGURATION ===
USER_HOME="$HOME"
WP_PATH="$USER_HOME/public_html"
BACKUP_PATH="$USER_HOME/_private_backups"
mkdir -p "$BACKUP_PATH"
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
BACKUP_FILE="wp_backup_${DATE}.tar"
# === Get DB credentials ===
WP_CONFIG="$WP_PATH/wp-config.php"
DB_NAME=$(grep DB_NAME "$WP_CONFIG" | cut -d "'" -f 4)
DB_USER=$(grep DB_USER "$WP_CONFIG" | cut -d "'" -f 4)
DB_PASS=$(grep DB_PASSWORD "$WP_CONFIG" | cut -d "'" -f 4)
DB_HOST=$(grep DB_HOST "$WP_CONFIG" | cut -d "'" -f 4)
echo "=== WordPress Site Export for Local Development ==="
echo "=== User: $(whoami) | Host: DomainsFoundry Managed WordPress Hosting ==="
echo ""
echo "Select export type:"
echo "1) FULL export (complete site including all uploads - best for exact replica)"
echo "2) SMALL export (excludes wp-content/uploads - faster download for development)"
echo ""
read -p "Enter choice (1 or 2): " BACKUP_TYPE
# Validate input
if [[ "$BACKUP_TYPE" != "1" && "$BACKUP_TYPE" != "2" ]]; then
echo "Invalid choice. Please enter 1 or 2."
exit 1
fi
if [[ "$BACKUP_TYPE" == "1" ]]; then
echo "✓ Selected: FULL export (complete WordPress site)"
BACKUP_FILE="wp_export_FULL_${DATE}.tar"
else
echo "✓ Selected: SMALL export (WordPress core + themes + plugins, no uploads)"
BACKUP_FILE="wp_export_SMALL_${DATE}.tar"
fi
# === Check space ===
SITE_SIZE_MB=$(du -sm "$WP_PATH" | awk '{print $1}')
DB_SIZE_MB=$(mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -e \
"SELECT CEIL(SUM(data_length + index_length)/1024/1024) FROM information_schema.tables WHERE table_schema='${DB_NAME}';" \
2>/dev/null | tail -n1)
if [[ -z "$DB_SIZE_MB" ]]; then DB_SIZE_MB=100; fi
REQUIRED_MB=$(( ($SITE_SIZE_MB + $DB_SIZE_MB) * 120 / 100 ))
AVAILABLE_MB=$(df -Pm "$BACKUP_PATH" | awk 'NR==2 {print $4}')
if (( AVAILABLE_MB < REQUIRED_MB )); then
echo "Not enough free space. Need ${REQUIRED_MB}MB, have ${AVAILABLE_MB}MB"
exit 1
fi
# === Step 1: Dump DB (Auto-detect charset and compress safely) ===
DB_DUMP_FILE="db_${DB_NAME}_${DATE}.sql.gz"
# Detect charset from MySQL
DB_CHARSET=$(mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -Nse \
"SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name='${DB_NAME}';" 2>/dev/null)
# Fallback if detection fails
if [[ -z "$DB_CHARSET" ]]; then
DB_CHARSET="utf8mb4"
fi
echo "──────────────────────────────────────────────"
echo "Dumping database (charset: $DB_CHARSET, compressed)..."
echo "This will NOT lock or freeze your live site."
echo "──────────────────────────────────────────────"
# Perform the dump safely
mysqldump -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" \
--default-character-set="$DB_CHARSET" \
--single-transaction --quick --lock-tables=false \
--routines --events --triggers \
| gzip -9 > "$BACKUP_PATH/$DB_DUMP_FILE"
# Check result
if [[ $? -ne 0 ]]; then
echo "❌ Database dump failed"
exit 1
else
echo "✅ Database dump complete: $BACKUP_PATH/$DB_DUMP_FILE"
fi
# === Step 2: Create TAR of WordPress files ===
echo "Exporting WordPress files from your DomainsFoundry hosting..."
if [[ "$BACKUP_TYPE" == "1" ]]; then
# FULL export - complete site for exact local replica
tar --exclude='cache/*' --exclude='*.log' \
-cvf "$BACKUP_PATH/$BACKUP_FILE" -C "$WP_PATH" . || {
echo "Export failed"; exit 1; }
else
# SMALL export - WordPress development essentials without large uploads
tar --exclude='wp-content/uploads/*' \
--exclude='wp-content/backup*' \
--exclude='wp-content/backups/*' \
--exclude='*.zip' \
--exclude='*.tar.gz' \
--exclude='*.sql' \
--exclude='*.sql.gz' \
--exclude='node_modules/*' \
--exclude='cache/*' \
--exclude='*.log' \
-cvf "$BACKUP_PATH/$BACKUP_FILE" -C "$WP_PATH" . || {
echo "Export failed"; exit 1; }
fi
# === Step 3: Add DB dump ===
tar -rf "$BACKUP_PATH/$BACKUP_FILE" -C "$BACKUP_PATH" "$DB_DUMP_FILE"
# === Step 4: Compress final TAR ===
echo "Compressing archive..."
gzip -9 "$BACKUP_PATH/$BACKUP_FILE"
# === Step 5: Cleanup ===
rm -f "$BACKUP_PATH/$DB_DUMP_FILE"
FINAL_FILE="$BACKUP_PATH/${BACKUP_FILE}.gz"
echo "✅ WordPress export complete! File saved to: $FINAL_FILE"
echo "? Export size: $(du -h "$FINAL_FILE" | awk '{print $1}')"
echo ""
echo "Next steps for local WordPress development:"
echo "1. Download this file via cPanel File Manager from: _private_backups/"
echo "2. Extract the .tar.gz file in your local WordPress directory"
echo "3. Import the .sql.gz database file into your local MySQL/MariaDB"
echo "4. Update wp-config.php with your local database credentials"
echo "5. Search-replace your live domain with localhost in the database"
echo "6. Delete this file via cPanel File Manager from: _private_backups/"
echo ""
echo "Your DomainsFoundry Managed WordPress Hosting site remains unchanged."
- Save the file and close the editor.
This makes sure that only you can run the script.
Step 3: Run Your Backup Script
Time to fire it up! Run the script manually using:
./wp_full_backup.sh
The process might take a few minutes, depending on how big your website is. Once it’s done, your backup will be waiting for you in the _private_backups folder. You can download it safely using cPanel’s File Manager or SFTP whenever you’re ready!
