Backup Website Terminal Instructions

Most effective and easiest way of backing up your website is in terminal. The process that I am about to show you is very easy. It may look like it is past your capabilities but it is not. If you follow these easy step by step instructions you will have a full backup to download to your computer or dropbox. Let get started.

Shell Access

The first thing that you will need is “shell access” to your user account on the server. To set this up ask your host provider for shell access. NOTE: not all providers provide shell access.

Shell access looks like this username@111.111.1.1. You will notice there is a username followed by an IP address. Every server has an IP address. This is how your computer knows where to find your server.

Password

After you enter your shell access string you will be asked for a password.

Only cool people share!

NOTE: You will not see the password being typed out. It is hidden for security reasons. 

Navigating Folders Directories in Terminal

The next thing that you will have to do is navigate to your website directory. For our clients here at A1WEBSITEPRO enter this string.

[code]cd ../../web[/code]

This will get you to the directory to perform the backups.

MySql Database Backup

Websites are mostly database driven. You have to get the database before you zip up all of your files. In order to get the database we use the “mysqldump” command in terminal. We will need a username and a password to the database before we can retrieve it. If you are on a WordPress that username and password is located in the wp-config.php file. Let me show you how to get that.

Type in “ls”. This will give you a list of folders and files in the main directory. It should look something like this if you are using WordPress.

Files directories terminal wordpress

 

Type in the following command.

[code]nano wp-config.php[/code]

nano wp-config

This will bring up the wp-config.php file located in wordpress. This is the “key” to your database. Scroll down the file by pressing “control v”. Look for a place that looks like this.

wp-config file in wordpress

You will need 3 things from this file.

  1. The database name.
  2. The username.
  3. The password.

Copy them down on a notepad somewhere so they will be easy to use.

Next press “control x” to exit the file. If it asks you if you want to save anything press the “n” key on your keyboard.

Mysqldump Command

Do not let the term mysqldump confuse you. You are NOT dumping or destroying your database. So using the example above I will show you how to export your database on your server.

Note: letters are case sensitive.  

[code]mysqldump -u username -p DBNAME>data.sql[/code]

After entering the above code you see a prompt for a password.

Note: you will not be able to see the password when you type it in.

What is this command doing? This is taking your entire database and storing it in a sql file called data.sql. This gets zipped with the rest of your files on the server.

Confirming Data File

To confirm that the file is on your server type in “ls” and press enter. There you should be able to see a file called data.sql.

 

Zipping All Files Together

The idea here is to zip all the files together so we can download a backup of our website with the database. Enter the following command in your terminal.

[code]zip -r bk.zip *[/code]

Then press your enter key on your keyboard.

This may take a few minutes to complete if you have a large website. After it completes you will see the letters stop running. Type in “ls” to make sure there is a bk.zip file on your server.

backup zip file of website

Downloading Your Backup

If you followed the instructions above you are ready to download your backup file. Go to your web browser and type in your website name followed by /bk.zip and hit enter.

Next you see a prompt to save the file. Click yes and make a note of where your computer is saving the file.

Deleting the Backup File

Never leave the backup file or database file on your server. For security purposes always remove these two files after you have finished downloading your full backup file.

Go to the Shell terminal and click ls. Here you will see the bk.zip file and the data.sql file. In the command line on the terminal type

[code]rm bk.zip data.sql[/code]

to remove both files. Then click ls to check and make sure that those two files do not exist. Then your task is complete.

Backup Website Terminal Instructions was last modified: March 10th, 2023 by Maximus Mccullough

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.