Backup a WordPress website manually from the command line
By Steve Claridge on 2025-08-10.
A friend has (had) a long-standing WordPress website that was left to rot, the domain name expired some time back so the website wasn't publicly visible. He wanted to back it up in case he wanted to resurrect it later.
I tried to view it via IP but WP itself wasn't even running. So I decided to just back up the theme, uploaded files and content manually. Here's what I did:
Backup files
This will back up all WordPress PHP files, theme files and any files that were uploaded when creating post or pages, e.g. images and videos.
First, SSH to the machine.
The common location for a WordPress installation ins /var/www/
So look in there are you will probably see a wordpress
or maybe a directory with the name of the website
you want to back up. Lets assume the directory the website is in is called thesite
.
We want to create a ZIP of everything to download, so:
- cd /var/www
- tar -cpvzf /tmp/wordpress.tar.gz thesite
Then download the single zipped file from the /tmp directory using either SCP from your local machine or something like FileZilla.
Backup the database
WordPress store the content you create in a mySQL database, so all Post or Page content goes in here, plus tags, metadata etc etc.
Do you know the username/password the the database? if not you can find it in the wp-config.php
, which is
in the root folder you backed up previously. Look for the following lines in wp-config.php
:
define('DB_NAME', 'database_name');
define('DB_USER', 'root');
define('DB_PASSWORD', 'the-password');
You can now extract and ZIP everything from the WordPress database using a single command line:
mysqldump -u root -p database_name | gzip > /tmp/database.tar.gz
Same as before, SCP/FileZilla the file from the box to your local machine.
This is everything you need to back up to rescue an old/stale WordPress installation.