Monday, October 26, 2020
Home Programming How to back up your website with the SSH command line

How to back up your website with the SSH command line

Backing up your website or blog can be an expensive and laborious task that requires various extensions or extra plans from your hosting provider – but it really doesn’t have to be.

Ad

If you have SSH access to your website, then it is easy to perform several high-level tasks remotely. This is how you back up your website using SSH in a command line session.

What is the SSH command line?

SSH allows you to talk directly to your web server. It doesn’t provide a great interface or a nice interface, just a straightforward powerful command line. This can be scary for some people, but the sheer power, speed, and level of automation it offers can be an absolute lifesaver and make moving sites incredibly easy.

Unfortunately, many shared hosts do not allow SSH to access your account by default. However, this is changing, and if you are using a Linux hosting service, you should have SSH access. If your website hosts GoDaddy, SSH should be enabled by default. If not, you can enable SSH in GoDaddy cPanel user interface. Other web hosts offer a similar feature.

At the same time, VPS and separate server web hosts allow SSH. Don’t know the difference? Check us out guide to web hosting services






Best Web Hosting Service: Shared, VPS and Dedicated
Are you looking for the best web hosting service for your needs? Here are our best recommendations for your blog or website.
Read more

to learn more.

How to use SSH on your computer

All three desktop operating systems have a command line interface that supports SSH.

Just open the interface and type the ssh command to use the related tools.

If you haven’t used the command line environment before, some of this may seem difficult. While there is currently no time to teach you all about SSH, here are a few shortcuts:

  1. Scroll up and down arrows to scroll through previously issued commands
  2. Press the tab key as you type a long filename – if the name is unique enough, it should complete itself

Once you’re happy with SSH, it’s time to start backing up your website.

Log in to your website via SSH

To get started, launch the SSH tool you want and type the following:

ssh [email protected]

You also use only the IP address. This is useful if you are using a web server that does not have a URL assigned to it, or if you are moving websites and the URL has changed.

ssh [email protected]

Enter the password when prompted. If you’ve never used SSH before, you may be surprised when typing your password doesn’t include anything on the screen.

Don’t worry, it’s for safety’s sake.

Once logged in, you will be prompted with a command such as the following:

-bash-3.2:~$

This means that everything is fine, so go ahead and continue with these commands.

Start by looking around and trying to navigate your web directory. Type:

ls

“List” current files and folders.

cd directoryname

change directory. In this case, I’m going to navigate to httpd the directory that is my website just. You can then ls again, just to be sure.

Access your website via SSH for data backup and restore

At this point, we are ready to begin SSH backup.

Use SSH to back up your website database

Because you are backing up your WordPress installation, you want to back up your database and files.

You need three bits of data to back up your database. Fortunately, if you have WordPress, all of these can be found in the wp-config.php file:

  1. Database name
  2. Database user
  3. Database password

(If you are using another database-based web application, see the installation instructions for this information.)

Then enter this simple command, replacing the username, table name, and backup file name if necessary:

mysqldump --add-drop-table -u [username] -p [tablename] > [backupfilename].sql

Press Enter, then type your password when prompted. Once you are done, you can enter a new one ls command to verify that the file is printed. Congratulations, all this data from your database as a single SQL file, ready to be backed up or imported elsewhere.

No access to the database via SSH

Assume that your database server runs on the same server that you maintain.

However, in GoDaddy, the MySQL database is stored on a remote server to which you do not have SSH access. In such cases, you will need to access PHPMyAdmin through the host’s cPanel, outside of this guide.

Backing up website data using SSH

Once the database is stored as a single file on the server, you can go ahead and back up your site via SSH. First, navigate (using the CD) to the directory where you want to create the backup. Next, use

tar -vcf yourbackupfilename.tar /directory/path

Back up your website with SSH

Consider this:

  • tar– General Linux compression format, similar to zip, but more powerful.
  • -vcf—Options that say “make a new archive and tell them what you are doing”.
  • tar—The name you selected for the archive
  • /directory/path—Specify the path to the website directory

The optional single-episode character can replace the file path and instruct the archive on everything. You can also use * as a “catch-all” application, but this excludes hidden files such as .htaccess, which is essential for WordPress.

Once done, you will have one TAR file consisting of all the files on your site.

At this point, you can connect via FTP and download the site archive.

Restoring a web page backup using SSH

Suppose the worst has happened and something has gone badly wrong on your site. You have a TAR file of everything you backed up last week, so you want to restore it.

First, log in via FTP and send the backup file to the root folder of your server.

Start by compressing all the files, unlike what we did to back them up:

tar -vxf yourbackupfilename.tar

WARNING: This will replace existing files!

The crucial difference here:

-vxf—Instructs tar to extract files instead of creating a new backup.

The final step is to suck the database back to where it was before. Start with blank database settings with the same password and table name as before. If you don’t have this, you’ll also need to change your site’s configuration settings.

Restore the database using:

mysql -u [username] -p [tablename] < [databasebackupfilename].sql

SSH website backups: Faster than web consoles and plug-ins

While a variety of tools and extensions have been released to help you back up your site, nothing is faster than SSH.

If you have an SSH connection to GoDaddy or who you host your site with, you can now back up your website. Want to know more? It's time to learn how to remotely manage a Linux server with SSH






How to remotely manage a Linux server with SSH
SSH is very functional, which is why it is a way to manage a remote server. Learn how to remotely manage a Linux server via SSH from a connection to software installation and file transfer.
Read more

.

Patriotic Hackershttps://patriotichackers.com
Patriotichackers.com is an online tech and life hacks website. You can get here all kinds of content on Simplified Technology and Crafts. So you can catch us on Social Media Platforms to stay updated with us.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments