NEWS • 18 July 2019

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 back up 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)
      • You will the database name, username and password. You can find these 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 text 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.
      • Paste the below mysqldump command 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.
  4. Backup the Website Files
    • Paste the below code into the terminal (don’t forget the full stop and slash). Name the backup file with the date it was taken. E.g. 10th October 2018 to be backup10102018.tar
    • tar -vcf backup24052018.tar ./
  5. Check everything has worked!
    • Do an ls -lah 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.

Back to all news