How to Automate WordPress Database Backups Using WP-CLI and Cron on Linux VPS
Hostinger vs. Contabo: Full Specifications Breakdown
Data verified from our lab benchmarks • Updated for 2026
| Feature / Metric | HostingerEditor's Choice UI | ContaboMax RAM Value |
|---|---|---|
| Starting Price | $2.99 / month (Web) | $4.99 / mo (VPS) | $5.50 / month (Cloud VPS S) |
| vCPU Cores | 1 to 8 vCPU (Dedicated resources) | 4 to 12 vCPU (High Core Count) |
| RAM Memory | 4 GB to 32 GB | 6 GB to 64 GB (Gigantic RAM) |
| Storage Technology | 50 GB – 400 GB NVMe SSD | 50 GB NVMe or 300 GB SSD |
| Traffic / Bandwidth | 4 TB to 32 TB | 32 TB Outgoing + Unlimited In |
| Control Panel & UI | hPanel (Ultra Modern & Easy) | cPanel, Plesk, Webmin, or CLI |
| Customer Support | 24/7 Live Chat & AI Support (Multi-lingual) | Email Ticket Support (German Business Hours) |
| Best For | Bloggers, WordPress Sites & Devs wanting easy UI | Heavy Database, Docker, Game Servers & SysAdmins |
| Money-Back Guarantee | 30-Day Money-Back Guarantee | 14-Day EU Statutory Cancellation |
| Official Links | Visit Hostinger | Visit Contabo |
Ditch bloated backup plugins that slow down your server. Learn how to automate zero-overhead WordPress database backups with WP-CLI, gzip, and cron on Linux VPS.
- Zero PHP memory overhead: bypasses web server timeouts entirely during large database exports
- Compresses database archives up to 85% smaller using gzip compression
- Automated retention policies prune old archives automatically to preserve disk space
The Flaws of WordPress Backup Plugins
Popular WordPress backup plugins (UpdraftPlus, BackWPup) execute inside the WordPress PHP runtime. When your WooCommerce database grows past 500MB with hundreds of thousands of order rows, these plugins frequently hit PHP max_execution_time or memory limits, causing database exports to fail silently or crashing your live website during execution.
Professional Linux sysadmins execute backups outside of the web server entirely using WP-CLI (the official command-line interface for WordPress) paired with standard Linux Cron daemons. This approach uses almost zero memory, executes in seconds, and never disrupts live visitors.
Step 1: Installing WP-CLI on Your VPS
SSH into your Hostinger or Contabo VPS as root:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
Step 2: Testing Manual Database Export
Navigate to your WordPress web root directory (e.g., /var/www/html):
cd /var/www/html
wp db export --allow-root test_backup.sql
WP-CLI reads your wp-config.php credentials automatically and dumps your database cleanly. Once verified, delete the test file:
rm test_backup.sql
Step 3: Creating the Automated Production Backup Script
Create a robust bash script that exports the database, compresses it with gzip, creates an archive directory, and purges backups older than 14 days:
sudo mkdir -p /var/backups/wordpress
sudo nano /usr/local/bin/backup-wp.sh
Paste the following script:
#!/bin/bash
# Configuration
WP_PATH="/var/www/html"
BACKUP_DIR="/var/backups/wordpress"
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
BACKUP_FILE="$BACKUP_DIR/wp_db_$TIMESTAMP.sql"
# Ensure backup directory exists
mkdir -p "$BACKUP_DIR"
# Export and compress database
cd "$WP_PATH" || exit 1
/usr/local/bin/wp db export "$BACKUP_FILE" --allow-root --quiet
gzip "$BACKUP_FILE"
# Log success
echo "[$TIMESTAMP] Backup created: $BACKUP_FILE.gz" >> "$BACKUP_DIR/backup.log"
# Prune archives older than 14 days
find "$BACKUP_DIR" -type f -name "wp_db_*.sql.gz" -mtime +14 -exec rm -f {} +
Make the script executable:
sudo chmod +x /usr/local/bin/backup-wp.sh
Step 4: Scheduling Nightly Automation with Cron
Open the system crontab editor:
sudo crontab -e
Add the following line to execute the backup every night at 3:00 AM:
0 3 * * * /usr/local/bin/backup-wp.sh > /dev/null 2>&1
Bonus: Offloading to Remote Contabo Storage VPS
To follow the 3-2-1 backup rule, add a single rsync command to the end of the script to copy the compressed .sql.gz file to an offsite Contabo Storage VPS over SSH keys!
Step 5: 1-Click Database Restoration
If disaster strikes or a bad plugin update corrupts your database, restoring your WordPress site takes one simple command:
gunzip < /var/backups/wordpress/wp_db_2026-12-24_03-00-00.sql.gz | wp db import - --allow-root --path=/var/www/html
WP-CLI + Cron vs. WordPress Backup Plugins
| Feature | WP-CLI + Cron Script | UpdraftPlus / Plugin Backups |
|---|---|---|
| PHP Memory & Timeout Risk | Zero (Runs natively in CLI) | High on large 1+ GB databases |
| Live Visitor Speed Impact | 0% | Can spike PHP-FPM CPU |
| Cost for S3 / Offsite Sync | $0 (Free with rsync/rclone) | $70+/yr Pro add-on |
Recommended Reading & Related Guides
Frequently Asked Questions (FAQ)
Does wp db export lock my WooCommerce tables while backing up?
Add --single-transaction to your wp db export flags for InnoDB tables so live WooCommerce orders continue writing smoothly without table locks.
Should I also back up wp-content/uploads?
Yes! Pair your nightly SQL dump with rsync -avz /var/www/html/wp-content/uploads/ so both your database and media library stay protected.
Summary
Using WP-CLI and Cron provides a bulletproof, zero-cost backup system that operates completely independently of WordPress plugins, guaranteeing that your valuable content and customer orders are perpetually safeguarded.
Video Walkthrough & Official References
How to Set Up an SSH Connection with Contabo VPS (Step-by-Step) • Contabo
Official External Documentation
Editorial Verdict: Pros & Cons
What We Love (Pros)
- Zero PHP memory overhead: bypasses web server timeouts entirely during large database exports
- Compresses database archives up to 85% smaller using gzip compression
- Automated retention policies prune old archives automatically to preserve disk space
Drawbacks (Cons)
- Requires basic SSH terminal familiarity to install WP-CLI and configure root/user crontabs
Written by Marcus Vance
Full-Stack Cloud Engineer
Alex and the ServerCraft engineering lab run routine benchmarks on over 25 web hosting providers, maintaining strict objectivity and reproducibility.
Recommended Next Reads
Hostinger WordPress Speed Optimization: How to Achieve 100/100 on PageSpeed Insights
A battle-tested blueprint to score 100 on Google Mobile PageSpeed Insights with Hostinger. Covers LiteSpeed Cache configuration, Object Cache, and Cloudflare CDN integration.
How to Enable Redis Object Cache on Hostinger for Millisecond Database Speeds
A complete guide to configuring Redis Object Caching on Hostinger WordPress hosting. Cut database query times from 800ms to 5ms for WooCommerce and dynamic sites.
Hostinger WooCommerce Speed Optimization: Complete High-Traffic Checklist
Transform your sluggish WooCommerce store into a conversion machine on Hostinger. Master Redis caching, database index tuning, cart fragmentation fixes, and Cloudflare APO.