Creating a Backup of WordPress Website Hosted on Linux VPS Using SSH

Creating a Backup of WordPress Website Hosted on Linux VPS Using SSH

In Linux servers, the directory path for hosted websites is ./var/www/html/ by default. You can use this path for creating backup files of the websites using SSH. The result with be an archived file in either tar or gzip format. In this article, learn how to create backup files of your WordPress website hosted on Centos 7 VPS Server and copy them to Ubuntu 16.04 Server using ssh and scp (Secure Copy). As you’ll see, there are more than one ways to do it. Pick the one that’s more convenient for you.

First Option

Open SSH and get prepared. First ensure that the remote user has write permission enabled to the backup directory. Otherwise, you’re going to see an error message. Also, make sure that are no files in the directory that matches the archive file you’re going to name. Otherwise, it will override the destination file and you’ll lose it.

Then, here are the steps involved in the first step:

Execute this command for creating the tar archive file from site directory -
Code:
$ tar –czvf mywebsitebackup.tar.gz /var/www/html/*
ssh.png


Now, check if you have backed the files up with this command -
Code:
$ tar –tf mywebsitebackup.tar.gz
Move the files to remote Ubuntu 16.04 server with this command -
Code:
$ scp –i ~/.ssh/id_rsa mywebsitebackup.tar.gz linuxuser@ubuntu16-hoststud:/backups
If you don’t have ssh keys configured but are able to log in via password, execute this command (you’ll be asked to provide the password) -
Code:
$ scp mywebsitebackup.tar.gz linuxuser@ubuntu16-hoststud:/backups
In this case, the backup of the WordPress has been moved to the remote Ubuntu server and named ‘mywebsitebackup.tar.gz’.

Second Option

The second option is even simpler than the first one. You’d be done in just one step. Open the SSH and execute this command:

Code:
$ tar -czvf - /var/www/html/* | ssh linuxuser@ubuntu16-hoststud "cd /home/linuxuser/backups
; cat > mywebsitebackup.tar.gz
Now log in to your remote server. You should see a file named mywebsitebackup.tar.gz.

If you want to copy the backup file and extract it at the same time, execute this command - $ tar -czvf - /var/www/html/* | ssh linuxuser@ubuntu16-hoststud "cd /home/linuxuser/backups ; tar -xzvf -"

In the remote server, you’ll see a folder created called ‘var’.

That’s how you create a backup of the WordPress website hosted on Linux VPS using SSH.
Author
kumkumsharma
Views
2,023
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from kumkumsharma

Top