How to automatically Backup All Your Databases on iFastNet cPanel Hosting
This guide will help you create an automated backup of all your MySQL databases using a simple script on your iFastNet CloudLinux cPanel server.
What This Script Does
- Automatically finds all databases in your cPanel account
- Creates individual SQL backup files for each database
- Compresses everything into a single ZIP file
- Saves the backup directly in your home directory (no folders to create)
- Names the backup file with date and time for easy identification
Before You Start
You'll need:
- Your cPanel username
- Your cPanel password (which is also your MySQL password on iFastNet)
- Access to File Manager or SSH
Getting Your Login Details
If you don't remember your cPanel credentials:
Method 1: Check Your Welcome Email
Look for the welcome email from iFastNet when you first signed up. It contains your login details.
Method 2: Client Area Login
- Go to your iFastNet client area
- Log in with your account credentials
- Find your hosting service
- View the cPanel login details
Method 3: Password Reset
If you've forgotten your password:
- Use the "Forgot Password" option on the cPanel login page
- Or log into your iFastNet client area to reset it
Method 4: Contact Support
If you're still having trouble:
- Visit: https://support.ifastnet.com/new_ticket.php
- First-time users: You'll need to register for a support account before creating your first ticket
- Create a ticket requesting your cPanel login details
Step-by-Step Instructions
Step 1: Access File Manager
- Log into your cPanel account
- Find and click on File Manager in the Files section
- Make sure you're in your home directory (you should see folders like
public_html, mail, etc.)
Step 2: Create the Backup Script
- In File Manager, click + File at the top
- Name the file:
backup_databases.sh
- Click Create New File
- Right-click on the new file and select Edit
- Copy and paste the entire script below into the file:
#!/bin/bash
# iFastNet cPanel Database Backup Script
# This script backs up all databases in your cPanel account
echo "================================================"
echo "iFastNet Database Backup Script"
echo "================================================"
# You only need to change these two lines:
CPANEL_USER="your_username_here"
MYSQL_PASSWORD="your_password_here"
# The rest is automatic - do not change
BACKUP_DIR="$HOME"
DATE=$(date +"%Y%m%d_%H%M%S")
BACKUP_FILE="database_backup_$DATE.zip"
TEMP_DIR="$HOME/temp_backup_$DATE"
# Create temporary directory
mkdir -p "$TEMP_DIR"
echo "Starting backup process..."
echo "Date/Time: $(date)"
echo "Backup will be saved as: $BACKUP_FILE"
echo ""
# Test MySQL connection first
echo "Testing database connection..."
mysql -u "$CPANEL_USER" -p"$MYSQL_PASSWORD" -e "SELECT 1;" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: Cannot connect to database!"
echo "Please check your username and password in the script."
echo ""
echo "Your username should be your cPanel username"
echo "Your password should be your cPanel password"
rm -rf "$TEMP_DIR"
exit 1
fi
echo "? Database connection successful!"
echo ""
# Get list of databases
echo "Finding your databases..."
DATABASES=$(mysql -u "$CPANEL_USER" -p"$MYSQL_PASSWORD" -e "SHOW DATABASES;" -s | grep -v "^information_schema$\|^performance_schema$\|^mysql$\|^sys$")
if [ -z "$DATABASES" ]; then
echo "No databases found in your account."
rm -rf "$TEMP_DIR"
exit 1
fi
echo "Found the following databases:"
for DB in $DATABASES; do
echo " • $DB"
done
echo ""
# Backup each database
SUCCESS_COUNT=0
TOTAL_COUNT=0
for DB in $DATABASES; do
TOTAL_COUNT=$((TOTAL_COUNT + 1))
echo "Backing up database: $DB"
# Create database backup
mysqldump -u "$CPANEL_USER" -p"$MYSQL_PASSWORD" \
--add-drop-table \
--create-options \
--disable-keys \
--extended-insert \
--single-transaction \
"$DB" > "$TEMP_DIR/${DB}.sql" 2>/dev/null
# Check if backup was successful
if [ $? -eq 0 ] && [ -s "$TEMP_DIR/${DB}.sql" ]; then
FILE_SIZE=$(du -h "$TEMP_DIR/${DB}.sql" | cut -f1)
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
echo " ? Success! ($FILE_SIZE)"
else
echo " ? Failed or empty"
rm -f "$TEMP_DIR/${DB}.sql"
fi
done
echo ""
echo "Backup Results: $SUCCESS_COUNT of $TOTAL_COUNT databases backed up"
echo ""
# Create ZIP file if we have successful backups
if [ $SUCCESS_COUNT -gt 0 ]; then
echo "Creating ZIP archive..."
cd "$TEMP_DIR"
zip -q "$BACKUP_DIR/$BACKUP_FILE" *.sql
if [ $? -eq 0 ]; then
# Clean up temporary files
rm -rf "$TEMP_DIR"
# Show final results
BACKUP_SIZE=$(du -h "$BACKUP_DIR/$BACKUP_FILE" | cut -f1)
echo "? Archive created successfully!"
echo ""
# Clean up old backups (older than 30 days)
echo "Cleaning up old backups (keeping last 30 days)..."
find "$HOME" -name "database_backup_*.zip" -type f -mtime +30 -delete 2>/dev/null
OLD_COUNT=$(find "$HOME" -name "database_backup_*.zip" -type f | wc -l)
echo "? Cleanup completed. Total backup files remaining: $OLD_COUNT"
echo ""
echo "================================================"
echo "BACKUP COMPLETED!"
echo "================================================"
echo "File location: $HOME/$BACKUP_FILE"
echo "File size: $BACKUP_SIZE"
echo "Databases included: $SUCCESS_COUNT"
echo ""
echo "You can download this file through cPanel File Manager"
echo "or find it in your home directory."
echo "================================================"
else
echo "? Failed to create ZIP file"
rm -rf "$TEMP_DIR"
exit 1
fi
else
echo "? No databases were successfully backed up"
rm -rf "$TEMP_DIR"
exit 1
fi
-
Important: Find these two lines near the top of the script:
CPANEL_USER="your_username_here"
MYSQL_PASSWORD="your_password_here"
-
Replace your_username_here with your actual cPanel username
-
Replace your_password_here with your actual cPanel password
-
Click Save Changes
Step 3: Make the Script Executable
- Right-click on the
backup_databases.sh file
- Select Permissions
- Check the Execute boxes for Owner, Group, and World
- Or simply set permissions to
755
- Click Change Permissions
Step 4: Run the Script
Option A: Test the Script First (Optional)
- Look for a Terminal icon in cPanel and click it (if available)
- Type:
./backup_databases.sh
- Press Enter to test that it works
Option B: Set Up Automatic Weekly Backups (Recommended)
Instead of running the script manually, you can set it to run automatically every week using cron jobs:
- In cPanel, find and click Cron Jobs
- In the Add New Cron Job section:
- Common Settings: Select "Once Per Week" from the dropdown
- Command: Enter:
/usr/bin/sh backup_databases.sh
- Click Add New Cron Job
Important Notes About Backup Frequency:
- Weekly backups are recommended maximum - Running backups daily or multiple times per week will quickly fill up your disk space
- Each backup can be several MB to GB depending on your database sizes
- The script automatically deletes backups older than 30 days to prevent disk space issues
- If you need more frequent backups, consider downloading and storing them locally instead of keeping them on the server
Example cron job settings:
- Minute: 0
- Hour: 2 (2 AM)
- Day: 1 (Monday)
- Month: * (every month)
- Weekday: * (any day of week, but Day=1 makes it Monday)
This will run your backup every Monday at 2 AM when server usage is typically low.
What Happens When You Run the Script
The script will:
- Test your database connection
- Show you which databases it found
- Backup each database individually
- Show the progress and file sizes
- Create a ZIP file with all backups
- Save it directly in your home directory with a name like:
database_backup_20240830_143022.zip
Finding Your Backup File
After the script runs successfully:
- Go to cPanel File Manager
- Look in your home directory (the main folder when you open File Manager)
- You'll see a file named
database_backup_[DATE]_[TIME].zip
- Right-click the file and select Download to save it to your computer
Troubleshooting
"Cannot connect to database" Error
- Double-check your cPanel username and password in the script
- Make sure you're using your cPanel credentials, not your iFastNet client area credentials
- Contact iFastNet support if the issue persists
"Permission denied" Error
- Make sure you set the file permissions to 755 (executable)
- The file should have execute permissions for all users
"No databases found" Message
- This usually means you don't have any databases created yet
- Check in cPanel > MySQL Databases to see if you have any databases
Script Won't Run
- Verify the script filename is exactly
backup_databases.sh
- Make sure you're running it from your home directory via cPanel Terminal
- Check that you have execute permissions on the file
Cron Job Not Running
- Make sure the command in your cron job is exactly:
/usr/bin/sh backup_databases.sh
- Check that your script has execute permissions (755)
- Verify your cron job timing settings are correct
- Look in cPanel > Cron Jobs to see if there are any error messages
Getting Help
If you encounter any issues:
- First-time support users: Register at https://support.ifastnet.com/new_ticket.php
- Existing users: Log in and create a new ticket
- Include details about:
- What error messages you're seeing
- Which step you're stuck on
- Your cPanel username (never include your password)
Security Note
Remember to:
- Keep your backup files secure
- Download them to your local computer for safe storage
- Delete old backup files from the server to save space
- Never share your cPanel password with anyone
CloudLinux Compatibility
This script is fully compatible with iFastNet's CloudLinux cPanel servers and uses standard MySQL commands that work within the CloudLinux security restrictions.