To automate WordPress backups on Hostinger without a plugin, use a short Bash script that runs WP-CLI’s database export and tar, then schedule it with an hPanel cron job. You’ll end up with a daily archive of your database, wp-content and wp-config.php, kept for about a week in a private folder outside the website.
Quick answer: Save a backup script in your Hostinger home folder, test it once over SSH, then run it daily with a Custom cron job in hPanel.
- Enable SSH in hPanel and connect to your account.
- Create
~/backupsand~/scriptsand lock them withchmod 700. - Save the script below as
~/scripts/wp-backup.shand make it executable. - Run it once and check the archive with
tar -ztvf. - In hPanel, add a Custom cron job that runs
/bin/bash /home/USERNAME/scripts/wp-backup.shdaily.
In this guide
- Before You Start
- Why Backup Plugins Fail on Shared and Cloud Hosting
- Step 1: Enable SSH and Find Your Paths
- Step 2: Test a Database Export by Hand
- Step 3: Create Private Folders for Backups and Scripts
- Step 4: Write the Backup and Retention Script
- Step 5: Run the Script Once and Check the Archive
- Step 6: Schedule the Backup with an hPanel Cron Job
- Step 7: Test a Restore
- If the Backup Doesn’t Run
- Frequently Asked Questions
- Next Steps
Backup plugins often crash once the database gets large or PHP hits a timeout, and they tie up the same PHP workers your visitors need. Running the backup in the shell avoids both problems.

Before You Start
- Plan and access: SSH access and WP-CLI, which Hostinger includes on its Premium, Business and Cloud hosting plans, plus your hPanel login.
- Time: about 20 minutes to set up and test.
- Disk space: archives count against your plan’s storage. With 7-day retention you keep about eight archives, so check that you have room for eight copies of your site.
- Off-site copy: backups stored on the same account are lost if the account is. Copy them elsewhere regularly (see the FAQ).
- Restores overwrite: the restore steps in Step 7 replace your current files and database. Practise them on a staging copy first.
Why Backup Plugins Fail on Shared and Cloud Hosting
Most backup plugins (UpdraftPlus, All-in-One WP Migration, BackupBuddy) run inside the PHP web process. When a scheduled backup starts, the plugin sends HTTP requests to its own site, loads large database tables into PHP memory, and tries to zip everything on the fly.
That approach fails in predictable ways:
- Execution timeouts: Hostinger plans cap
max_execution_time(six to eight minutes at most, depending on the plan). If yourwp_postsorwp_postmetatables are large, PHP stops the script mid-dump. - Out-of-memory crashes: SQL dumps run through PHP can exceed 256MB or 512MB limits and end with a fatal
Allowed memory size exhaustederror. - Slower pages for visitors: archiving files in the web process uses PHP workers, so real visitors wait in a queue for pages to load.
WP-CLI (the official WordPress command-line tool) avoids all of this. It hands the database export to mysqldump, and the script packs files with tar; both run in the shell, not in the web server. That is faster, uses little memory and never ties up PHP workers.
Step 1: Enable SSH and Find Your Paths
You need terminal access to your Hostinger account first.
- Log in to hPanel.
- Go to Websites > Dashboard for your domain.
- In the sidebar, open Advanced > SSH Access.
- Switch SSH to Enabled if it’s off.
- Note your SSH IP, Port (Hostinger uses 65002) and Username.
Open a terminal on your own computer and connect:
ssh -p 65002 u123456789@203.0.113.10Once you are in, check your paths and that WP-CLI responds:
which wp
pwdwhich wp prints the WP-CLI path (the examples below assume /usr/local/bin/wp; use whatever path it reports). pwd prints your home folder, such as /home/u123456789. Your site files sit at /home/u123456789/domains/yourdomain.com/public_html.
Step 2: Test a Database Export by Hand
Before writing the script, run one export manually to confirm that WP-CLI can reach the database. Go into your site root:
cd ~/domains/yourdomain.com/public_htmlExport to a test file in your home folder (not inside public_html, where anyone could download it):
wp db export ~/test-backup.sql --add-drop-tableWP-CLI prints a “Success” line with the file name when the export works. The --add-drop-table option makes the dump drop each existing table before recreating it, so a restore doesn’t fail on duplicate entries.
Delete the test file:
rm ~/test-backup.sqlStep 3: Create Private Folders for Backups and Scripts
Never keep backup files inside public_html. Anyone scanning your domain for .sql or .zip files could download your customer data and database password.
Create private folders in your home folder, outside the web root:
mkdir -p ~/backups
mkdir -p ~/scripts
chmod 700 ~/backups ~/scriptsPermission 700 means only your own account can open these folders. The commands print nothing when they succeed; ls -ld ~/backups should show drwx------.
Step 4: Write the Backup and Retention Script
The script dumps the database, packs it together with wp-content and wp-config.php into a compressed .tar.gz archive, and deletes archives older than 7 days so disk usage doesn’t keep growing.
Create the script file in the nano editor:
nano ~/scripts/wp-backup.shPaste the following script. Change DOMAIN_NAME to your exact folder name under ~/domains/:
#!/bin/bash
# Configuration
DOMAIN_NAME="yourdomain.com"
WP_PATH="$HOME/domains/$DOMAIN_NAME/public_html"
BACKUP_DIR="$HOME/backups"
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
RETENTION_DAYS=7
# Set paths
DB_FILE="$BACKUP_DIR/db_${DATE}.sql"
ARCHIVE_FILE="$BACKUP_DIR/backup_${DOMAIN_NAME}_${DATE}.tar.gz"
# Navigate to WP directory
cd "$WP_PATH" || exit 1
# Export database via WP-CLI and stop if the export fails
if ! /usr/local/bin/wp db export "$DB_FILE" --add-drop-table --single-transaction --quiet; then
echo "Database export failed!" >&2
rm -f "$DB_FILE"
exit 1
fi
# Create compressed archive containing wp-content, wp-config.php and the database dump
if ! tar -czf "$ARCHIVE_FILE" -C "$WP_PATH" wp-content wp-config.php -C "$BACKUP_DIR" "db_${DATE}.sql"; then
echo "Archive creation failed!" >&2
rm -f "$DB_FILE" "$ARCHIVE_FILE"
exit 1
fi
# Remove uncompressed SQL dump
rm -f "$DB_FILE"
# Remove archives older than RETENTION_DAYS
find "$BACKUP_DIR" -type f -name "backup_${DOMAIN_NAME}_*.tar.gz" -mtime +"$RETENTION_DAYS" -delete
echo "Backup completed: $ARCHIVE_FILE"Save with Ctrl + O, press Enter, and exit with Ctrl + X.
Why only wp-content, wp-config.php and the database? WordPress core files (wp-admin, wp-includes and the root PHP files) can be downloaded again at any time, as the WordPress backup documentation explains. Backing up only what is unique to your site keeps the archive smaller and the job faster. The --single-transaction option lets mysqldump take a consistent snapshot of InnoDB tables without locking them.
Make the script executable:
chmod +x ~/scripts/wp-backup.shStep 5: Run the Script Once and Check the Archive
Run the script manually to catch typos in paths:
~/scripts/wp-backup.shIf it worked, the last line reads Backup completed: followed by the archive path. List the backup folder:
ls -lh ~/backupsYou should see one .tar.gz file with today’s date in its name. List its contents without unpacking it, to confirm the database dump and your site files are inside:
tar -ztvf ~/backups/backup_yourdomain.com_*.tar.gz | head -n 20The listing should include wp-content/ paths, wp-config.php and a db_ file ending in .sql.
Step 6: Schedule the Backup with an hPanel Cron Job
Hostinger manages cron jobs (scheduled commands) through hPanel, so set the schedule there rather than with crontab -e.
- In hPanel, go to Advanced > Cron Jobs.
- For the job type, choose Custom.
- In the command field, enter the full path to your script:
/bin/bash /home/u123456789/scripts/wp-backup.shReplace u123456789 with your Hostinger username. Leave shell redirections such as > /dev/null 2>&1 out of this field: Hostinger’s cron form doesn’t accept special characters, and hPanel lets you view each job’s output anyway. If you want a log file, add the redirection inside the script instead.
- Set your schedule. For a daily backup at 3:00 AM (hPanel cron schedules run on UTC):
- Minute:
0 - Hour:
3 - Day of Month:
* - Month:
* - Day of Week:
*
- Minute:
- Click Save.
The day after, open the job’s output from the cron job list in hPanel. It should end with the Backup completed: line, and ls -lh ~/backups should show a new archive. The guide to set up a real cron job in Hostinger covers the same hPanel screen in more detail.
Step 7: Test a Restore
An untested backup is a guess. Practise the restore on a staging copy first; see how to set up a WordPress staging site in Hostinger hPanel.
To restore over SSH, unpack the archive into a temporary folder, sync wp-content back into place, and import the database dump. The archive also contains wp-config.php; copy it back only if the live one is missing or damaged. Replace the dates in the file names with those of the archive you are restoring:
# 1. Unpack the archive into a temporary directory
mkdir -p ~/restore_tmp
tar -xzf ~/backups/backup_yourdomain.com_2026-09-01_03-00-00.tar.gz -C ~/restore_tmp
# 2. Restore wp-content (--delete removes files that are not in the backup)
rsync -a --delete ~/restore_tmp/wp-content/ ~/domains/yourdomain.com/public_html/wp-content/
# 3. Save the current database, then import the backup via WP-CLI
cd ~/domains/yourdomain.com/public_html
wp db export ~/backups/pre-restore.sql
wp db import ~/restore_tmp/db_2026-09-01_03-00-00.sql
# 4. Clean up temporary files
rm -rf ~/restore_tmpThen flush caches and temporary cached data (transients):
wp cache flush
wp transient delete --allLoad the site and log in to wp-admin to confirm the restored content. For a full manual restore, including an empty or broken site, follow the guide to restore a WordPress backup over SSH on Hostinger.
If the Backup Doesn’t Run
- Cron output shows
wp: command not found, or WP-CLI uses the wrong PHP version: cron doesn’t always load your full shell environment. Use absolute paths, as shown below. - Cron output shows “No such file or directory” for the
cdline:DOMAIN_NAMEdoesn’t match your folder under~/domains/. Check it withls ~/domains. - “Database export failed!”: run the
wp db exportcommand from Step 2 by hand in the site root to see the full error. - “Archive creation failed!” with “file changed as we read it”: a cache plugin was writing files while
tarread them, whichtarreports as an error. Schedule the job for a quieter hour, or add--exclude=wp-content/cacheright after the archive name in thetarline. - Backups stop when the disk fills up: lower
RETENTION_DAYSor move older archives off the server.
To use absolute paths, replace the export line in the script with this one (check both paths with which php and which wp):
/usr/bin/php /usr/local/bin/wp db export "$DB_FILE" --path="$WP_PATH" --add-drop-table --single-transaction --quietPassing --path="$WP_PATH" makes WP-CLI find your wp-config.php no matter which folder cron starts in.
Frequently Asked Questions
Does this backup method use many Hostinger inodes?
No, barely any. Each backup is a single .tar.gz file, and older archives are deleted automatically by the find -mtime +7 -delete line. That means you only use one inode (file entry) per kept archive, about eight at any time.
Can I copy these backups to another server or S3?
Yes. If rclone or the AWS CLI is available on your plan, add an rclone copy or aws s3 cp command at the end of wp-backup.sh. If you have your own storage server, add rsync -avz ~/backups/ user@remote:/storage/backups/ to push archives off the account right after they are created.
Will this script slow down my site during busy hours?
Not much. mysqldump runs directly against MySQL without using the web server’s PHP workers, and --single-transaction avoids locking InnoDB tables. It still uses CPU and disk activity that count toward your plan’s limits, so schedule it for a quiet hour.
What happens if a database table is locked or crashed?
The script stops without creating a broken archive. wp db export exits with an error code when a table fails, and the script checks that code, deletes the partial dump and exits before compressing. Check the cron output for “Database export failed!” to catch this.
Next Steps
Check the cron output after the first scheduled run, and confirm a new archive appears each day. Then set up an off-site copy, and practise a full restore on staging once, so you know the steps before you need them.

