Backing up your WordPress site is essential, especially if it’s hosted on a DigitalOcean VPS. This guide will walk you through backing up both your WordPress files and database.
Step 1: Connect to Your DigitalOcean VPS
First, connect to your VPS via SSH:
ssh root@your_droplet_ip
Replace your_droplet_ip
with your VPS’s IP address.
Step 2: Back Up WordPress Files
Navigate to the directory where WordPress is installed, typically /var/www/html
:
cd /var/www/html
Then create a compressed archive of your WordPress files:
tar -czvf wordpress_files_backup_$(date +%F).tar.gz *
This command creates an archive named wordpress_files_backup_<today’s_date>.tar.gz
.
Step 3: Back Up the WordPress Database
To back up the database, first find the credentials in wp-config.php
:
nano wp-config.php
Once you have the database name, user, and password, use mysqldump
:
mysqldump -u your_db_user -p your_db_name > wordpress_db_backup_$(date +%F).sql
You will be prompted for the database password, and it will create a file named wordpress_db_backup_<today’s_date>.sql
.
Step 4: Securely Transfer Your Backups to Another Computer
Now that you have your backup files, use scp
to securely transfer them to your local machine:
scp root@your_droplet_ip:/var/www/html/wordpress_files_backup_$(date +%F).tar.gz /local/backup/directory/
scp root@your_droplet_ip:/var/www/html/wordpress_db_backup_$(date +%F).sql /local/backup/directory/
Replace /local/backup/directory/
with the directory path on your local machine where you want to store the backups. This will securely copy your backups from the VPS to your local system for safekeeping.
With this setup, you have both your WordPress files and database safely backed up, ensuring your site is protected against data loss.
Leave a Reply