How To Make a WordPress Database Backup – Guidelines
Today in this article we will see different techniques of how To Make a WordPress Database Backup without plugin. We will see Database backup using a manual approach and using an automation approach.
You must be wondering if we can manually generate a backup of your WordPress database without using a plugin.
We will see an approach where we don’t need to install any external plugin or manually do any operation.
There could be multiple legitimate reasons for you not to use the plugin
You May Want to Minimize Plugin Use?
You may Want to Minimize Plugin Use due to any of the below reasons,
- You may be concerned about a number of the WordPress plugins your website is utilizing.
- Plugin use may slower your site you have an increased chance of a plugin conflict taking down your site, or a compromised plugin creating a security hole in your site.
- You may want easy to managed customized Backup Approach.
- You are concerned about website security while using a backup plugin
This approach doesn’t need any plugins if you are more concerned about plugins affecting the performance of your website unnecessarily.
If you are a programmer and know a little bit of coding, then you can write simple few lines of code and implement the back functionality on your own.
You can rapidly build a database backup anytime you need one if you are familiar with the manual process.
We’ll demonstrate how to manually configure a WordPress database backup in this article.
There are various manual ways and automated ways which can be used to generate backup.
- Using File Explorer
- Using code script – C# SSH.NET or Python script
- Using Plugin
- Using Manual tools like Filezilla etc.
I will be elaborating on at least 5 different techniques of database backup in the article.
However today we will only focus on the approach where you write a C# script to download the files directly from the WordPress file explorer location or backup location.
What is SFTP
SFTP (SSH File Transfer Protocol) is a secure file transfer protocol. It runs over the SSH protocol. It supports the full security and authentication functionality of SSH.
We will cover how to use SFTP-supported libraries i.e SSH.NET library
Worpdress – Connect to Wodpress backup via SFTP
SSH.NET provides SFTPClient class that lets you connect to the SFTP server securely and access files for
read, write, upload, or download purposes,
Below the sample code read the FTP file and write their name on the console.
using (var client = new SftpClient("****", "user", "****"))
{
client.Connect();
ListDirectory(client, ".");
foreach (var file in files)
{
Console.WriteLine(file.FullName);
}
}
The above ListDirectory uses the default path to fetch a file from the SFTP server.
WordPress File Download using FTP
Downloading the file from a remote file path is pretty simple once the connection is established successfully.
Use the below code to download the file via stream
using (var client = new SftpClient("****", "user", "****"))
{
client.Connect();
ListDirectory(client, ".");
foreach (var file in files)
{
Console.WriteLine(file.FullName);
using (Stream stream = File.Create($"{destinationPath}{"/"}{ file.Name}"))
{
client.DownloadFile(file.FullName, fileStream);
}
}
client.Disconnect();
}
In the above code,
destinationPath – Is the file path where the file will be downloaded via SFTP and FTP
localDirectoryFilePath – File path where the file will be downloaded to the local path.
Automate WordPress backup using Task scheduler
Once you complete your exe development as above, then it’s all about setting up the exe and executing it on your laptop/machine on the scheduled configuration.
You can configure database backup daily or monthly as needed.
Delete WordPress backup files after Download
If you are interested to delete the backup database, then please use the below way to delete the file,
using (Stream fileStream = File.Create($"{destinationPath}{"/"}{ file.Name}"))
{
client.DownloadFile(file.FullName, fileStream);
client.DeleteFile(file.FullName);
}
Kindly visit the below article for more details on how to run exe using the task scheduler as below,
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.