Table of Contents
Introduction
In this comprehensive guide, we'll walk you through the step-by-step process of how to back up WordPress manually via the command line.
In today's digital age, a website is a valuable asset, and ensuring its data is safe should be a top priority. While many WordPress users rely on automated backup plugins, there are situations where manual backups become necessary. Manual backups provide a deeper level of control and understanding of the process.
In addition, it's crucial to always maintain a working copy of your website and never solely rely on any web hosting company, even trusted providers like Hostney, to handle your backups.
Step 1: Open an SSH Connection
To begin the manual backup process, you'll need to establish a Secure Shell (SSH) connection to your web server. SSH provides a secure way to access your server's command line.
On Windows:
Open Your Terminal: Launch your terminal application. You can use an application like PuTTY.
Please refer to our guide for instructions on how to use PuTTY. See PuTTY's website for more information about the application itself.
On Linux:
Connect to Your Server: Use the ssh
command followed by your server's IP address or hostname and your username:
ssh username@your_server_ip_or_hostname
Replace username
with your actual username and your_server_ip_or_hostname
with your server's address.
Enter Your Password: You'll be prompted to enter your password to establish the SSH connection. Once authenticated, you'll have command-line access to your server.
Use Your SSH Private Key: Many web hosting providers, such as Hostney, offer a more secure approach to connecting to your terminal server. You can enhance security by installing your private key to authenticate your SSH session.
Hosting your website with Hostney allows you to connect to your terminal session through the Hostney Control Panel without any additional applications. See our knowledge base for more information.
Step 2: Back Up Your MySQL Database
Now that you have an SSH connection, you can access your WordPress database for backup. You'll need to back up your MySQL database with your database credentials.
If you host your website with Hostney, you can grab this information by navigating to 'Hosting' > 'MySQL Databases'.
Create a Database Dump: To create a MySQL dump of your database, use the following command:
mysqldump -u your_username -p your_database_name > backup.sql
Replace your_username
and your_database_name
as before. This command exports your database to a file named backup.sql
.
Ensure that you back up your MySQL database outside of the root folder to avoid exposing it to the internet.
Step 3: Back Up Your WordPress Folder
To back up your WordPress website's files, you must compress the public_html
folder. This folder contains all your website's content, themes, plugins, and uploads.
If your web hosting provider, like Hostney, uses a unique directory structure for your hosting plan, be sure to ask them for clarification on the location of your website's root directory.
1. Navigate to the Folder: Use the cd
command to navigate to the public_html
directory:
cd /path/to/your/public_html
Replace /path/to/your/public_html
with the actual path to your website's root folder.
2. Back up your data with a Tarball: To create a compressed archive of the folder, use the tar
command:
tar -czvf backup.tar.gz .
This command creates a backup.tar.gz
file containing all the files and directories within public_html
.
Make sure you use the period at the end of the line. It is not a typo; that tells your server that you want to compress the data in the current directory.
Step 4: Download the Backup with WinSCP
Finally, you can download the backup files to your local computer using the WinSCP (Windows Secure Copy) client.
- Download and Install WinSCP: If you haven't already, download and install WinSCP on your local computer.
- Launch WinSCP: Run WinSCP and configure a new session by entering your server's IP address or hostname, your SSH username, and selecting the "SFTP" protocol. To learn more about WinSCP, check out our Upload Your Content guide.
- Connect to Your Server: Click "Login" and enter your SSH password when prompted.
- Navigate to Your Backup: In the left pane (your local files), navigate to the folder where you want to save the backup. In the right pane (remote server), navigate to the directory where you stored the
backup.tar.gz
file. - Transfer the Backup: To transfer the backup to your local machine, select the
backup.tar.gz
file on the remote server and press F5 or drag and drop the file to the local machine. - Navigate to Your Database Backup: Similarly, repeat the transfer steps for the
backup.sql
file to ensure both your website files and database backup are safely stored on your local machine.
Conclusion
Manually backing up your WordPress website may seem complex, but it provides a robust way to safeguard your valuable data. By following the steps outlined in this guide, you've learned how to open an SSH connection, access and export your MySQL database, compress your website files, and download the backup using WinSCP. Regularly performing these manual backups will help ensure the security and integrity of your WordPress site, providing peace of mind in the event of unexpected data loss or issues.
Keep in mind that when you back up your WordPress site, these archive files can also be used for manually migrating your website to a new server.
Not a customer yet? Sign up for our free 30-day trial.