Using the Terminal to Take a Website Backup

If you've ever updated a plugin or theme and something has gone terribly wrong, you'll know the benefits of having a failsafe backup protocol to employ before each major update. But, you'll probably also know taking a copy via FTP can be a slow process, particularly when the site is large and image-heavy. At TWK, we like to use the terminal to quickly and effectively back up our websites before updating - and the best part is, it couldn't be easier to do!

Step-by-step guide on how to backup a WordPress site:

  1. Open the terminal
  2. SSH into your site using the server username, password and IP – ssh [email protected]
    • It will prompt for the server password, type it in (note you won’t see the cursor move but it is typing) and hit enter.
  3. Backup the Database using a mySQL dump
    • Use cd public_html to navigate the root of the WordPress install (this is where we will save the backups)
    • Paste the below mysqldump code into the terminal replacing username with the database username and dbname with the database name. Name the backup file with the date it was taken. E.g. 10th October 2018 to be backup10102018.sql
    • mysqldump –add-drop-table -u username -p dbname > backup23052018.sql. 
    • It will prompt for the database password, type it in (note you won’t see the cursor move but it is typing) and hit enter.
      • You can find the database name and database username in the wp-config.php file which is saved in the root WordPress install.
      • To see this in the terminal you can open the built in code editor in the terminal by navigating to the root of the WordPress install and typing vi wp-config.php . Make a note of these and then hit escape and type :q to close the text editor.
  4. Backup the Website Files
    • Paste the below code into the terminal (don’t forget the full stop). Name the backup file with the date it was taken. E.g. 10th October 2018 to be backup10102018.sql
    • tar -vcf backup24052018.tar .
  5. Check everything has worked!
    • Do an ls command to check that the backup files are there and you’re done.

You are now safe to update your site and plugins with the peace of mind that you can revert back to the backup at any time.

Get in Touch
Latest Tweet

We will be closing the office for our annual Christmas Party at 3pm today. We will be back in the office from 9am t… https://t.co/87BloIjcDN