This PHP script automates full cPanel backups and transfers them to your preferred destination (FTP server or home directory). Designed for reliability and security, it's perfect for website owners and administrators.
Automated backups for normal cPanel users (no root access required).
This script is designed for shared hosting accounts where:
- You can run cron jobs in cPanel
- Your files are outside
public_html - Your host may block cPanel UAPI tokens
- Try cPanel UAPI first (if token is available)
Backup::fullbackup_to_homedirfor cPanel-managed home-directory backupsBackup::fullbackup_to_ftpwhen an enabled FTP destination is configured
- Fallback to native PHP backup when UAPI is blocked
- Create local backup archive (
.zipor.tar.gz) - Upload backups to one or more destinations:
- Local (keep in your account)
- FTP
- SFTP (if
ssh2extension exists) - Google Drive (via
rclone) - Dropbox (via
rclone) - S3-compatible storage (via
rclone)
- Send success/failure email
- Rotate logs and keep a limited number of local backups
- PHP 7.4+
- cPanel cron access
- Script stored outside
public_html - Optional:
curlextension for UAPI modeftpextension for FTP uploadssh2extension for SFTP uploadrclonebinary for Google Drive / Dropbox / S3 (and generic cloud remotes)
/home/your_cpanel_user/
├── backups/
│ ├── backup.php
│ ├── config.php
│ ├── config.php.example
│ ├── logs/
│ ├── artifacts/
│ └── tmp/
└── public_html/
Upload all script files to a folder like:
/home/your_cpanel_user/backups/
Do not place this script inside
public_html.
cp config.php.example config.phpOpen config.php and edit:
engine(autois recommended)native.home_dirnative.include_pathsnative.databases(optional but recommended)destinations- notification email
/usr/local/bin/php /home/your_cpanel_user/backups/backup.php --dry-run
/usr/local/bin/php /home/your_cpanel_user/backups/backup.phpDaily at 2 AM:
0 2 * * * /usr/local/bin/php /home/your_cpanel_user/backups/backup.php >> /dev/null 2>&1- Uses UAPI if available and working.
- If only local/home-dir storage is enabled, cPanel creates the full backup in the account home directory.
- If FTP is the enabled remote destination, cPanel transfers the full backup directly to FTP.
- Automatically falls back to native backup if UAPI fails.
- Force cPanel UAPI backup trigger.
- Fails if host blocks API token or endpoint.
- Set
cpanel.backup_destinationtohomedir,ftp, orauto. - UAPI FTP mode uses the first enabled FTP destination.
- Never calls UAPI.
- Uses pure PHP backup logic:
- Copies selected folders
- Dumps selected MySQL databases
- Packages everything into one archive
You can enable multiple destinations at once.
Keeps archives in storage.local_dir.
In UAPI mode, cPanel can transfer the full account backup directly via Backup::fullbackup_to_ftp.
In native mode, the script creates a local archive first and uploads it with PHP's FTP extension.
Uses PHP ssh2 extension.
Uses rclone remote config. Set destination type to google_drive, dropbox, s3, or rclone.
Example destination:
[
'name' => 'Google Drive',
'type' => 'google_drive',
'enabled' => true,
'remote' => 'gdrive',
'path' => 'cPanel-Backups',
]In native mode, add each database in native.databases:
[
'name' => 'cpuser_wpdb',
'host' => 'localhost',
'port' => 3306,
'user' => 'cpuser_wpuser',
'pass' => 'your-db-password',
]If databases is empty, only files are backed up.
- Logs are saved to
logging.file - Log rotation:
logging.max_size+logging.keep - Local backup retention:
storage.keep_local
Use:
'engine' => 'native'- Make sure
rcloneis installed on your hosting environment - Confirm the remote name in config (
remote) - Test command in terminal (if shell access exists):
rclone lsd <remote>:
Your hosting PHP may not include ssh2 extension. Use FTP or rclone-based destination instead.
Use absolute paths in cron and config.
- Keep script and config outside
public_html - Use file permissions:
chmod 640 config.php - Use strong destination passwords
- Do not commit real credentials to Git
- Test restore process regularly
Recommended Reading:
The Importance of Regular Backups for Your Website
Need a managed solution?
Explore our Business Backup Service
MIT
For assistance: