How to back up WordPress

9/19/2025
2 min read

Why Backing Up a WordPress Site is Essential

Backing up a WordPress site is critical to protect your website from data loss caused by hacking, server crashes, or accidental deletions. Imagine this: a company I worked with lost their entire WordPress site after a ransomware attack. They had no backup, which resulted in months of lost content and a significant hit to their business. A proper backup plan could have saved them from this disaster.

In this guide, we’ll walk you through how to backup a WordPress site, including its files and database, so you can restore it quickly if needed.


Step 1: Backup WordPress Files

WordPress files include themes, plugins, and media uploads, typically stored in /var/www/html. Use the following command to back them up:

sudo tar -czvf wordpress-files-backup.tar.gz /var/www/html

This creates a compressed file named wordpress-files-backup.tar.gz.


Step 2: Backup the WordPress Database

WordPress uses a MySQL or MariaDB database to store content and settings. Export the database using mysqldump:

sudo mysqldump -u root -p wordpress_db > wordpress-db-backup.sql

Replace wordpress_db with your database name. You’ll be prompted for the database root password.


Step 3: Store Backups Securely

Transfer the backup files to a secure location, such as an external drive or cloud storage:

scp wordpress-files-backup.tar.gz wordpress-db-backup.sql user@remote-server:/path/to/backup/

Step 4: Automate WordPress Backups

To ensure regular backups, set up a cron job:

  1. Open the crontab editor:crontab -e
  2. Add the following lines to back up files and the database daily:0 2 * * * tar -czvf /path/to/backup/wordpress-files-$(date +\%F).tar.gz /var/www/html 0 2 * * * mysqldump -u root -p'yourpassword' wordpress_db > /path/to/backup/wordpress-db-$(date +\%F).sql

Restoring a WordPress Site

To restore your WordPress site, follow these steps:

  1. Extract the WordPress files backup:sudo tar -xzvf wordpress-files-backup.tar.gz -C /
  2. Import the database backup:mysql -u root -p wordpress_db < wordpress-db-backup.sql
  3. Adjust file permissions:sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html

By following this guide, you can ensure your WordPress site is always protected. For a more comprehensive guide on backing up an entire server, check out our Ubuntu Server Backup Guide.


Volodymyr Huzii - Software Developer

About the Author

Volodymyr Huzii

Software Developer with 6+ years of full-stack experience, specializing in .NET, Vue.js, and modern web technologies. I focus on building highly secure, scalable, and performant software solutions that protect against modern cyber threats.

Skilled in developing secure SaaS applications, and integrating security best practices into every layer of the application stack. Expert in building applications that prioritize data protection and system integrity.

I work confidently across AWS and Azure environments, setting up secure CI/CD pipelines, and delivering robust, responsive, and high-performing applications with enterprise-grade security standards.

Strong collaborative mindset, proven ability to work with security teams and cross-functional teams, and a reputation for delivering secure solutions efficiently and reliably.

Safe Web Academy

Empowering individuals and organizations with cutting-edge cybersecurity knowledge and practical defense strategies.

© 2025 Safe Web Academy. All rights reserved. Securing the digital world.