Creating a website backup using terminal and command line

Reading Time: 6 minutes

The security and durability of your digital assets are critical considerations in the dynamic field of web administration. Making routine backups is one of the fundamental habits that each watchful website owner should adopt. But there is a reliable and simple method that uses the terminal and command line, as opposed to depending on sophisticated software programs or third-party applications.

Key takeaways

The primary takeaways found in this post include the following:

  • In terms of control and flexibility, why making a website backup via terminal and command line can be the optimal decision for seasoned admins
  • An in-depth look at the prerequisites that should have been establish before making a website backup
  • How to create a website backup using terminal and command line in step-by-step fashion
  • An understanding of why a sound website management strategy calls for frequent website backups

About making a website backup via terminal and command line

You can use the terminal and command line to create a backup of your website by following the instructions in this article. We will demystify the process so that website owners with varying degrees of technical expertise can utilize it, debunking popular myths that claim these kinds of practices are only for tech-savvy users. At the conclusion of this adventure, you will have both a dependable backup of your website and renewed confidence in using these crucial tools.

Come along as we explore the depths of terminal commands and debunk the misconception that your digital sanctuary can only be safely protected by sophisticated backup solutions. It's time to arm yourself with information, take charge of your website's security, and start using the terminal and command line to make easy backups.

An in-depth review of the prerequisites to establish before making a website backup

When creating a website backup using the terminal and command line, there are a few essential requirements that you need to ensure are met to guarantee a smooth and effective process. These requirements encompass both the technical aspects and best practices for securing your website data. Let's delve into the essential requirements.

When you make sure these requirements are satisfied, you can create a robust and reliable website backup strategy using the terminal and command line. This approach not only simplifies the backup process but also empowers you with greater control over the security and accessibility of your website data.

Access to terminal and command line interface

To perform website backups using the terminal and command line, you need access to a terminal and command line interface on your web hosting server. These tools are typically available for users with Secure Shell (SSH) access. Ensure you have the credentials and permissions to use the command line.

Basic knowledge of terminal commands

Familiarity with basic terminal commands is beneficial. While this article will guide you through the specific commands needed for website backups, having a foundational understanding of commands like cd (change directory), cp (copy), and mv (move) will make the process smoother.

Sufficient disk space

Before initiating a backup, ensure that there is sufficient disk space available on your server to store the backup files. Running out of disk space during the backup process could lead to incomplete backups and potential data corruption.

Backup storage location

It's crucial to store backups offsite — in other words — on a different server than the one the website is currently running on. This action ensures that your data is recoverable even during server failures or other issues. Identify a reliable external storage location or utilize cloud storage services to store your backups.

Regular backup schedule

A regular backup schedule is a required for maintaining the availability of the latest version of your website data, should your have a need to restore it from a point-in-time copy. Determine how often you need to perform backups based on the pace and volume of changes to your website's content.

Automation tools (optional)

While not mandatory, using automation tools can significantly streamline the backup process. Consider implementing cron jobs or scheduling tasks to automate your backup routine, reducing the need for manual intervention.

Testing your website backups by fulling restoring a website from them

Test the data integrity of your backups to ensure they work as expected should you need to employ them in any scenario. Testing a website backup involves restoring a backup to a separate environment to confirm that it contains all the necessary files and data.

Why should you consider using the terminal and command line methods

The command line and terminal methods provide efficient and direct interactions with your web server. Leveraging command line instructions allows for a more granular and customized approach to creating backups. These methods are especially suited for website admins who prefer a hands-on approach and want full control over the backup process.

Why storing your website backup on a different web server than the original web server is important

Storing your backups offsite is a critical for ensuring that your data remains recoverable even in the event of a server failure. Let's explore how you can create and store a website backup on a different web server rather than the original web server.

Step #1. Gather essential Information

Before initiating the backup process, gather the following information to ensure a smooth execution:

  • SSH credentials. Ensure you have the correct Secure Shell (SSH) credentials for accessing your server.
  • Document root location. Identify the location of your website's files on the server (for example /home/user/domain/html).
  • Database credentials. Have the necessary database credentials, including the username and password. Database credentials are typically available in the MySQL portion of the client portal associated with your web hosting plan. MySQL remains one of the most popular databases used for websites, representing the the "M" in LAMP Stack.

Step #2. Connect to your server

Before initiating the backup process, connect to your server using SSH. This step ensures a secure connection for executing commands:

ssh your_username@your_server_ip

Step #3. Navigate to your website directory

Move to the directory where your website files are stored:

cd /path/to/your/website

Step #4. Create a database backup

Use commands to export your website's database to a file:

mysqldump -u your_db_username -p your_db_name > database_backup.sql

Replace your_db_username, your_db_name, and your_descriptive_backup_name.sql with your actual database username, database name, and a descriptive name for the SQL dump.

Step #5. Archive website files

Create a compressed archive of your website files:

tar -czvf website_backup.tar.gz *

Step #6. Transfer a website backup to remote server

scp database_backup.sql your_username@remote_server_ip:/path/to/backup/location/
scp website_backup.tar.gz your_username@remote_server_ip:/path/to/backup/location/

By following these steps, you can create and store a backup on any server, enhancing the security and redundancy of your website data.

Step #7. Safely deleting website backups from your web server

Congratulations! You've successfully created a backup of your website using the terminal and command line, and it's now securely stored on your computer. Now, there are some cleanup activities necessary to complete the process and ensure optimal server performance. Removing the backup files from your server is essential. Here is a step-by-step guide on safely deleting backups from your server.

7.1. Verify your website backup

Before proceeding with deletion, double-check that your website backup files are found on the destination server or computer as expected. Ensure that the files are intact and accessible. This precautionary step ensures you have a reliable copy of your website data before removing it from the server.

7.2. Connect to your web server

Use SSH to connect to your server, just as you did when creating the backup. This secure connection allows you to execute commands on your server:

ssh your_username@your_server_ip

7.3. Navigate to the backup directory

Move to the directory where your backup files are stored on the server. If you followed our previous guide, this might be the directory you used to create the backups:

cd /path/to/backup/location/

7.4. List website backup files

Confirm the presence of the backup files in the directory. Use the ls (list) command to display the list of files located in the directory:

ls

Ensure that the displayed files match the names of the backup files you created. This step helps avoid accidental deletion of the wrong files.

7.5. Remove backup files

Use the rm (remove) command to delete the backup files from the server. If you have both a database backup file and a compressed archive of your website files, execute the following commands:

rm database_backup.sql
rm website_backup.tar.gz

Remember to insert the actual file names of your backup files instead of using the placeholders shown above. Be cautious while using the rm command, as it permanently deletes files.

7.6. Verify the deletion of all backup files

Check that all files have been deleted as expected by listing the directory's contents again using the ls command:

ls

The deletion was successful if the directory is empty or no longer contains the backup files.

Deleting the backup files from your server is an important task in maintaining a healthy and organized hosting environment. Securely storing backups on your computer and removing them from the server reduces the risk of unintended access or modification.

Remember, the safety of your website data is paramount. Regularly creating offsite backups and removing them from the server once stored elsewhere contribute to a robust data protection strategy.

A sound website management strategy calls for frequent website backups

Safeguarding your website with regular backups is a fundamental aspect of responsible website ownership. By utilizing the terminal and command line, you can achieve this without the need for complex tools or third-party software.

Remember, the key to having an adequate backup policy is storing them offsite. Liquid Web offers solutions such as cPanel backup and offsite backups that align with best practices for data security. Before concluding, consider the top six best practices for data backup to ensure your backup strategy is comprehensive and resilient.

Make a wise choice for your website's security. Explore Liquid Web's hosting products and services, designed with the reliability and performance your website requires built into our hosting architecture. Order your hosting plan from Liquid Web today and take the first step towards a secure and resilient online presence. Remember, a well-executed backup strategy is not just about protection — it's about providing website owners peace of mind.

Avatar for Haritha Jacob

About the Author: Haritha Jacob

Latest Articles

Innovative armor — exploring ThreatDown’s impact on cyber defense

Read Article

Using a Cloudflare Argo Tunnel with load balancing

Read Article

Controlling PHP settings with a custom php.ini file

Read Article

Linux dos2unix command syntax — removing hidden Windows characters from files

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article