⏲️ Estimated reading time: 3 min
Daily WordPress Backup via Cron Job: Ultimate HelpZone Guide
Automating backups for your WordPress site is essential for security, stability, and peace of mind. In this post, you’ll learn how to set up a daily backup for your WordPress files using a cron job on a VPS or cPanel server.
📌 Protect your WordPress site with daily automatic file backups using cron jobs. This guide shows you how to back up your files every night and manage storage efficiently all without plugins.
🧰 Beginner-Friendly Setup Guide (Start Here!)
If you’re new to managing servers or WordPress file structures, follow these simple steps first:
Step 1: Connect to Your Server
Use an SSH client like PuTTY or your VPS panel to access your server via root:
ssh root@your-server-ip
Step 2: Locate Your WordPress Folder
Usually found in:
/home/your-username/public_html
Run this to verify:
ls /home/your-username/public_html
If you see folders like wp-content
, wp-admin
, and wp-includes
, you’re in the right place.
Step 3: Install a Text Editor (Optional)
If your VPS doesn’t have nano
, install it first:
yum install nano # For CentOS/RHEL
apt install nano # For Ubuntu/Debian

🔧 Step-by-Step: Schedule WordPress File Backups with Cron
1. 📁 Define Your Backup Structure
- WordPress Path:
/home/username/public_html
- Backup Destination:
/home/username/backups/wp-files
First, run this command to create the backup directory:
mkdir -p /home/username/backups/wp-files
2. 📝 Create the Shell Script
Next, you need to create a shell script that handles the backup process.
nano /root/backup_wp_files.sh
Then, paste the following code:
#!/bin/bash
WP_DIR="/home/username/public_html"
BACKUP_DIR="/home/username/backups/wp-files"
FILENAME="wp-files-$(date +%F).tar.gz"
tar -czf $BACKUP_DIR/$FILENAME $WP_DIR
# Remove backups older than 7 days
find $BACKUP_DIR -type f -name "*.tar.gz" -mtime +7 -exec rm {} \;
Exit with CTRL+X
, confirm with Y
, and save the file.
3. 🔐 Make the Script Executable
Before scheduling, make the script executable:
chmod +x /root/backup_wp_files.sh
4. ⏱️ Schedule the Cron Job
Now, edit the crontab to schedule the job:
crontab -e
After that, add the following line to execute the script daily at 3 AM:
0 3 * * * /root/backup_wp_files.sh > /dev/null 2>&1
This configuration ensures the script runs silently, without sending unnecessary notifications.
✅ How It Works
Every day at 3:00 AM:
- Cron triggers the backup script.
- As a result, your entire WordPress directory is compressed.
- The archive is saved in
/home/username/backups/wp-files/
with the current date. - Additionally, backups older than 7 days are automatically deleted.
Here is an example of what a backup file might look like:
/home/username/backups/wp-files/wp-files-2025-06-12.tar.gz
🧪 Optional: Enable Logging for Debugging
If you’d prefer to log the output instead of suppressing it, modify the cron line as follows:
0 3 * * * /root/backup_wp_files.sh >> /var/log/wp_backup.log 2>&1
🔔For more tutorials like this, consider subscribing to our blog.
📩 Do you have questions or suggestions? Leave a comment or contact us!
🏷️ Tags: WordPress backup, cron job, VPS, Linux, server automation, file backup, shell script, daily backup, WordPress security, website maintenance
📢 Hashtags: #WordPressBackup, #CronJob, #WebsiteSecurity, #ServerAutomation, #LinuxTips, #WPBackup, #DailyBackup, #WebHosting, #SysAdminTips, #HelpZone
🛡️ Final Thoughts
Setting up an automated backup system for your WordPress files ensures that you’re never caught off guard by accidental file loss or server failure. With just a simple script and cron job, your website becomes significantly more resilient and protected. Furthermore, you gain peace of mind knowing your data is consistently backed up without manual effort.
Only logged-in users can submit reports.
Discover more from HelpZone
Subscribe to get the latest posts sent to your email.