Wordpress Manually Backup and Migrate

There are many plugins that can backup your wordpress website and migrate it. But because I have modified some files of wordpress, I have to manually backup them. Here is how I do it.

The following solution only works if you serve a wordpress on a linux vps, and you are working on another Linux.

#Intro

There are two main parts of a wordpress website, one is the unzipped wordpress directory, the other is database. Sometimes you want to backup log, too.

#Backup wordpress folder

Backup wordpress directory is easy, just copy the whole directory would do the job, or you can compress it. Using FTP or scp, or even the website itself(HTTPS) to transit/download it, so many options.

But remember, you are working on the server which serve websites. And the compressing might consume a lot of cpu resources, which might slow down your websites. So it's better that you transfer the files to the backup/new server without compression.

scp: secure copy, you can take it as cp command between two internet node. Here is a detailed document about scp.

To secure copy files from Alice to Bob, you need either

scp -P 22 alicefile bob@bobexample.com:/home/bob/destination

run on Alice's computer, or

scp -P 22 alice@aliceexample.com:/home/alice/alicefile ./destination

on Bob's computer.

To minimize the influence to the website server, we recommand using the second one, fetch remote wordpress directory to destination.

To copy a folder, you need -r:

scp -P 22 -r acytoo@test.acytoo.com:/home/acytoo/wordpress ./

It should take a long time since wordpress directory contains lots of files, so be patient, or you can pack your website first. tar is the command that comes with most linux distribution that help packing files(with compressions if with -z)

tar -cf wordpress.tar wordpress

you will get a uncompressed, packed file, named wordpress.tar. Since no compression is involved, the operation does not consume much cpu, and runs quick. Now you can transfer the packed file much quicker.

scp -P 22 acytoo@test.acytoo.com:/home/acytoo/wordpress.tar ./

Then unpacking it:

tar -xf wordpress.tar

#Backup database

There's no fixed method on how to backup a database. Based on the database system you use, there are at least two ways of backing up a database. Search google for your database, here's a document from MariaDB.

If your website's database is on a different server(not the server where you put wordpress directory), the migration is actually done, check your wp-config.php and serve the website.

How to backup a MariaDB? The most easy way is using mysqldump

Yes, the command starts with mysql but works on MariaDB.

mysqldump -u <DB username> -p <DB tablename> > <DB backup file, like db20220812.sql>

#Backup log files

Same as wordpress folder, simply copy them to somewhere else.