
Building a reliable and good-ranking WordPress site is a time consuming task that takes a lot of human resources to achieve. However, losing WordPress data is as fast as a single site crash, security attack, or server failure. This means you can lose a 10-year-old high-ranking WordPress site in 10 minutes. To solve this, WordPress backups ensure that you can recover your site in all situations.
A 3-2-1 backup strategy is a data backup and recovery method that creates multiple copies of your WordPress site to ensure safety and availability if a data loss or site crashes occurs. Unlike regular backups, a 3-2-1 strategy involves abiding by multiple storage methods to keep your WordPress backups recoverable and up to date.
This article explains how you can efficiently back up a WordPress website using a 3-2-1 strategy. You are to create multiple files and database copies, store them on different media, and automate the procedure to keep your WordPress backups up to date.
Before you begin, be sure to:
Deploy a OneClick WordPress server using the Vultr marketplace application
If you have an existing WordPress instance, make sure you have terminal access to perform backup tasks
Use SSH, access the WordPress server as a non-root user with sudo privileges
Switch to the non-root sudo user account. For example webadmin
This article uses the example values
webadminand the WordPress domainexample. Replace the values with your actual WordPress server details
A full WordPress backup consists of the data application files and a copy of the full database including the tables and table data. In this section, perform a full WordPress backup to implement a 3-2-1 strategy as described below.
Find and switch to the WordPress web root directory. For example /var/www/html/
If you’re unsure of the WordPress directory, view your web server virtual host configuration. For example, for Nginx, check the /etc/nginx/sites-available/ directory
Run the following command to search your WordPress domain name in all available files and find the exact configuration file
View the WordPress configuration file and take note of the root directory path
Switch to the directory
List the directory and verify that all WordPress files are available
Output:
To make a backup of the WordPress files. Switch to the parent directory
Copy the WordPress files to a separate directory such as your user home with a different filename such as wp-files-backup
The above command makes a copy of all WordPress files and preserves all permissions to your user home directory with the new directory name wp-files-backup. To uniquely identify your backup file, add the server timestamp to the filename while copying the files as below:
Switch to your user home directory and verify that the WordPress files are available
List files in the directory
Output:
To safely store the WordPress files backup, archive the directory using a compression format such as gunzip to create a .tar.gz file
When you archive and compress the WordPress files backup directory, the file size reduces, and file safety improves with little to no changes in the archive format unless extracted.
Long list files and verify that the wp-files-backup.tar.gz is available in your directory
View your WordPress wp-config.php file
Find the following section
Keep note of the database name in the DB_NAME directive, the database user, and password used to connect WordPress to your database.
Log in to your MySQL database server using the WordPress database user and password
When prompted, enter the database user password
Verify that the WordPress database is available
Exit the MySQL console
Using mysqldump, export the WordPress database to a readable file such as wpdatabase.sql
When successful, list your directory files and verify that a new wpdatabase.sql file is available
To avoid making changes to the file, archive and compress the file to a format such as .tar.gz
Verify that the database archive file is available in your directory
To organize your full WordPress backup files, create a new directory named fullwpbackup
Move all WordPress backup archive files to the directory
List files and verify that only archive files are available in the directory
To perform WordPress backups using your administrator dashboard, install a compatible plugin and use it to create a full backup file that includes the database and WordPress files. Many backup plugins are available in the WordPress repository, depending on your choice, visit the following resources to perform backups using a WordPress plugin.
A 3-2-1 backup strategy follows the standard below:
By following the strategy correctly, your WordPress backup files are safe from any possible form of data corruption. In case your WordPress site crashes or suffers a massive security breach, you can roll back changes to the last stable state and work out solutions to prevent a similar scenario from happening again.
In this section, implement the 3-2-1 WordPress backup storage on your server as described in the steps below.
To implement the 3 backup storage types method, save multiple copies of the backup files and apply different compression mechanisms. For example, keep a single .tar.gz copy, a .zip variant, and a non-archived backup copy as described in the following steps.
Switch to your user home directory
Long list files and verify that your wpdatabase.sql file, fullwpbackup and wp-files-backup directories are available
Output:
Create the first full backup archive .tar.gz archive file
The fullwpbackup.tar.gz includes files with the same .tar.gz archive format. To apply a different format, it must match the files to avoid any forms of data corruption
Create a second full backup archive using the .zip format, wpdatabase.sql file and wp-files-backup directory
Long list files to verify that both .tar.gz and .zip WordPress archive files are available in the directory
Output:
The original wp-files-backup and wpdatabase.sql apply as the third backup copies. To create another archive, use a different format such as tar.xz
Compress the file
You have implemented three WordPress backup copies through which you can recover your WordPress site in case of any failure. To safeguard the copies, separate them into different storage volumes.
When your server crashes, any attached secondary storage volumes can function normally and you can re-attach them to your server when troubleshooting is complete. In this section, attach a Vultr block storage volume to your server and store your WordPress backups to two different volumes as described below.
backupdisk in the /media/ directorySwitch to the Vultr Block Storage volume directory
Create a new file hellobackup.txt to verify that you can write to the disk
When created, switch back to your user home directory
Create a new directory WP-Backup
Copy the WordPress tar.gz and .zip archive files to the directory
Copy wp-files-backup and wpdatabase.sql to the directory
List the directory files and verify that all copies are available
Output:
Copy the WP-Backup directory to the Vultr block storage volume
To append the server timestamp on the directory name, adjust the command to:
List the volume files and verify that the directory is available
You have applied the two storage volumes backup method. The WordPress backup files are available on your server storage volume and the attached Vultr Block Storage volume. In case of any server failure, you can recover WordPress files by accessing the block storage volume.
Computing instances often crash in a batch, in case your hosted server and block storage volumes fail, you can recover your WordPress site using a local backup file. Or, you can apply an S3-compatible Vultr Object Storage instance to work as an off-site destination. In this case, your WordPress backup files become available in different locations than your server.
Depending on your WordPress backup file size, implement the off-site storage method as described in the steps below.
You can download your WordPress backup files to your computer using various file transfer methods such as FTP, SFTP, or SCP. When the transfer is successful, a local copy of your WordPress backup files is available on your computer and you can recover it by re-uploading the files to the server.
Open a new terminal window
Establish an SFTP connection to your server
List files in the working directory
Verify that the WP-Backup directory is available
Download the WP-Backup directory to your computer
Monitor the download progress, when complete, end the SFTP connection
Using your file explorer, find and open the WP-Backup directory on your computer
Verify that all WordPress backup copies are available
Vultr Object Storage is an S3-compatible instance that is fully independent from your server infrastructure. You can create buckets, and upload your WordPress backup files for recovery in case of any server failure. Implement the off-site backup method with Vultr Object Storage as described in the steps below.
Deploy a Vultr Object Storage instance and copy the Access Key and Secret Key from the instance dashboard.
Install s3cmd on the server
Configure s3cmd with your Vultr Object Storage endpoint, Access and Secret keys
In your server SSH session, list the available buckets linked to your Vultr Object storage
If no configuration is available, run s3cmd --configure to connect to your Vultr Object Storage
Create a new bucket named wordpress-backups
Upload the WP-Backup directory to the wordpress-backups bucket
When the upload is complete, list all objects in the wordpress-backups bucket to verify that the transfer is complete
Or, navigate to your Vultr Object Storage control panel and view the bucket objects
Verify that the WP-Backup directory files are available in your wordpress-backups bucket
Delete the WP-Backup directory to free space on your main server storage volume
You have implemented the off-site backup method to your WordPress backup files. To further widen your off-site implementation, you can upload copies of your WordPress backup to public storage services such as Google Drive, Dropbox, Mega, among others.
Running the WordPress 3-2-1 backup strategy is a time consuming process. To save time and automate the process, but keep monitoring any changes, use CronJob to schedule automatic tasks to backup your WordPress database, and files as described below.
Using a text editor such as nano, create a new auto-backup.sh script in your user home directory.
Add the following configurations to the file
Save and close the file
The above script creates the latest full WordPress backup that includes the CMS files and database. The full backup exports to the auto-backups directory, then, 2 archive format copies generate from the files to make 3 available copies.
The # 2 different storage volumes section exports the generated WP-Backup directory to your Vultr block storage volume and keeps the original copy available on your server.
In the #off-site storage section, the s3cmd tool uploads a copy of the WP-Backup directory to your Vultr Object Storage bucket. When the upload completes successfully without any error, the WP-Backup gets deleted from the main server storage to free up space.
Files older than 2 weeks are auto-deleted from the directory to create space for newer backups. To increase the age of deleted files, edit the OldFiles section values.
Run the above script to verify that it works correctly.
When complete, view files in the auto-backups directory
Verify that all files include the server time stamp to create unique backup files
To automate the above script to run every week, edit your crontab configuration
Add the following directive to the file
Save and close the file
The above Cron task runs the auto-backup.sh script every Sunday at 01:00. You can change the time and date to match a date with low WordPress site activity to create the latest weekly backup copy. For more information, visit the how to use the Cron Task Scheduler resource.
In this article, you implemented a WordPress 3-2-1 backup strategy that creates a good disaster recovery plan. Depending on your preferences, you must ensure that your WordPress backup files are up to date to clear any errors that may result from updates or security breaches on your site.
WordPress is a highly extensible CMS, to implement more solutions on your server, visit the following resources:
0 Comments
Be the first to comment and share your perspective with the community.