{"id":344,"date":"2024-06-06T11:36:45","date_gmt":"2024-06-06T11:36:45","guid":{"rendered":"https:\/\/249host.com\/tutorials\/?p=344"},"modified":"2024-06-20T10:35:27","modified_gmt":"2024-06-20T10:35:27","slug":"creating-a-website-backup-using-terminal","status":"publish","type":"post","link":"https:\/\/249host.com\/tutorials\/creating-a-website-backup-using-terminal\/","title":{"rendered":"Creating a website backup using terminal and command line"},"content":{"rendered":"<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"\">\n<h2 id=\"h-about-making-a-website-backup-via-terminal-and-command-line\" class=\"Heading__SHeading-sc-o0nhd6-0\">About making a website backup via terminal and command line<\/h2>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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.<\/p>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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&#8217;s time to arm yourself with information, take charge of your website&#8217;s security, and start using the terminal and command line to make easy backups.<\/p>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"\">\n<h2 id=\"h-an-in-depth-review-of-the-prerequisites-to-establish-before-making-a-website-backup\" class=\"Heading__SHeading-sc-o0nhd6-0\">An in-depth review of the prerequisites to establish before making a website backup<\/h2>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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&#8217;s delve into the essential requirements.<\/p>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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 <a href=\"https:\/\/www.249host.com\/\">website<\/a> data.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-access-to-terminal-and-command-line-interface\" class=\"Heading__SHeading-sc-o0nhd6-0\">Access to terminal and command line interface<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 class=\"Heading__SHeading-sc-o0nhd6-0\">Basic knowledge of terminal commands<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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 <em><strong>cd<\/strong><\/em> (change directory), <strong><em>cp<\/em><\/strong> (copy), and <strong><em>mv<\/em><\/strong> (move) will make the process smoother.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-sufficient-disk-space\" class=\"Heading__SHeading-sc-o0nhd6-0\">Sufficient disk space<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-backup-storage-location\" class=\"Heading__SHeading-sc-o0nhd6-0\">Backup storage location<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">It&#8217;s crucial to store backups offsite \u2014 in other words \u2014 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.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-regular-backup-schedule\" class=\"Heading__SHeading-sc-o0nhd6-0\">Regular backup schedule<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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&#8217;s content.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-automation-tools-optional\" class=\"Heading__SHeading-sc-o0nhd6-0\">Automation tools (optional)<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-testing-your-website-backups-by-fulling-restoring-a-website-from-them\" class=\"Heading__SHeading-sc-o0nhd6-0\">Testing your website backups by fulling restoring a website from them<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-why-should-you-consider-using-the-terminal-and-command-line-methods\" class=\"Heading__SHeading-sc-o0nhd6-0\">Why should you consider using the terminal and command line methods<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-why-storing-your-website-backup-on-a-different-web-server-than-the-original-web-server-is-important\" class=\"Heading__SHeading-sc-o0nhd6-0\">Why storing your website backup on a different web server than the original web server is important<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Storing your backups offsite is a critical for ensuring that your data remains recoverable even in the event of a server failure. Let&#8217;s explore how you can create and store a website backup on a different web server rather than the original web server.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"\">\n<h2 id=\"h-step-1-gather-essential-information\" class=\"Heading__SHeading-sc-o0nhd6-0\">Step #1. Gather essential Information<\/h2>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Before initiating the backup process, gather the following information to ensure a smooth execution:<\/p>\n<\/div>\n<div data-lw-block-type=\"list\" data-lw-block-attributes=\"\">\n<ul class=\"list-disc list-outside\">\n<li><strong>SSH credentials.<\/strong> Ensure you have the correct <strong>Secure Shell (SSH) credentials for accessing your server.<\/strong><\/li>\n<li><strong>Document root location.<\/strong> Identify the location of your website&#8217;s files on the server (for example <strong><em>\/home\/user\/domain\/html<\/em><\/strong>).<\/li>\n<li><strong>Database credentials.<\/strong> 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, <strong>representing the the &#8220;M&#8221; in LAMP Stack<\/strong>.<\/li>\n<\/ul>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"\">\n<h2 id=\"h-step-2-connect-to-your-server\" class=\"Heading__SHeading-sc-o0nhd6-0\">Step #2. Connect to your server<\/h2>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Before initiating the backup process, connect to your server using SSH. This step ensures a secure connection for executing commands:<\/p>\n<\/div>\n<div data-lw-block-type=\"code\" data-lw-block-attributes=\"\">\n<pre class=\"wp-block-code\"><code>ssh your_username@your_server_ip<\/code><\/pre>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"\">\n<h2 id=\"h-step-3-navigate-to-your-website-directory\" class=\"Heading__SHeading-sc-o0nhd6-0\">Step #3. Navigate to your website directory<\/h2>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Move to the directory where your website files are stored:<\/p>\n<\/div>\n<div data-lw-block-type=\"code\" data-lw-block-attributes=\"\">\n<pre class=\"wp-block-code\"><code>cd \/path\/to\/your\/website<\/code><\/pre>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"\">\n<h2 id=\"h-step-4-create-a-database-backup\" class=\"Heading__SHeading-sc-o0nhd6-0\">Step #4. Create a database backup<\/h2>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Use commands to export your website&#8217;s database to a file:<\/p>\n<\/div>\n<div data-lw-block-type=\"code\" data-lw-block-attributes=\"\">\n<pre class=\"wp-block-code\"><code>mysqldump -u your_db_username -p your_db_name &gt; database_backup.sql<\/code><\/pre>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Replace <strong><em>your_db_username<\/em><\/strong>, <strong><em>your_db_name<\/em><\/strong>, and <strong><em>your_descriptive_backup_name.sql<\/em><\/strong> with your actual database username, database name, and a descriptive name for the SQL dump.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"\">\n<h2 id=\"h-step-5-archive-website-files\" class=\"Heading__SHeading-sc-o0nhd6-0\">Step #5. Archive website files<\/h2>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Create a compressed archive of your website files:<\/p>\n<\/div>\n<div data-lw-block-type=\"code\" data-lw-block-attributes=\"\">\n<pre class=\"wp-block-code\"><code>tar -czvf website_backup.tar.gz *<\/code><\/pre>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"\">\n<h2 id=\"h-step-6-transfer-a-website-backup-to-remote-server\" class=\"Heading__SHeading-sc-o0nhd6-0\">Step #6. Transfer a website backup to remote server<\/h2>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Use <strong>SCP (Secure Copy) to securely transfer your backup<\/strong> to a remote server:<\/p>\n<\/div>\n<div data-lw-block-type=\"code\" data-lw-block-attributes=\"\">\n<pre class=\"wp-block-code\"><code>scp database_backup.sql your_username@remote_server_ip:\/path\/to\/backup\/location\/\r\nscp website_backup.tar.gz your_username@remote_server_ip:\/path\/to\/backup\/location\/<\/code><\/pre>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">By following these steps, you can create and store a backup on any server, enhancing the security and redundancy of your website data.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"\">\n<h2 id=\"h-step-7-safely-deleting-website-backups-from-your-web-server\" class=\"Heading__SHeading-sc-o0nhd6-0\">Step #7. Safely deleting website backups from your web server<\/h2>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Congratulations! You&#8217;ve successfully created a backup of your website using the terminal and command line, and it&#8217;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.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-7-1-verify-your-website-backup\" class=\"Heading__SHeading-sc-o0nhd6-0\">7.1. Verify your website backup<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Before proceeding with deletion, double-check that your website backup files are found on the destination <a href=\"https:\/\/www.squarebrothers.com\/dedicated-server-india\/\" target=\"_blank\" rel=\"noopener\">server<\/a> 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.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-7-2-connect-to-your-web-server\" class=\"Heading__SHeading-sc-o0nhd6-0\">7.2. Connect to your web server<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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:<\/p>\n<\/div>\n<div data-lw-block-type=\"code\" data-lw-block-attributes=\"\">\n<pre class=\"wp-block-code\"><code>ssh your_username@your_server_ip<\/code><\/pre>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-7-3-navigate-to-the-backup-directory\" class=\"Heading__SHeading-sc-o0nhd6-0\">7.3. Navigate to the backup directory<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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:<\/p>\n<\/div>\n<div data-lw-block-type=\"code\" data-lw-block-attributes=\"\">\n<pre class=\"wp-block-code\"><code>cd \/path\/to\/backup\/location\/<\/code><\/pre>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-7-4-list-website-backup-files\" class=\"Heading__SHeading-sc-o0nhd6-0\">7.4. List website backup files<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Confirm the presence of the backup files in the directory. Use the <strong><em>ls<\/em><\/strong> (list) command to display the list of files located in the directory:<\/p>\n<\/div>\n<div data-lw-block-type=\"code\" data-lw-block-attributes=\"\">\n<pre class=\"wp-block-code\"><code>ls<\/code><\/pre>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Ensure that the displayed files match the names of the backup files you created. This step helps avoid accidental deletion of the wrong files.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-7-5-remove-backup-files\" class=\"Heading__SHeading-sc-o0nhd6-0\">7.5. Remove backup files<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Use the <strong><em>rm<\/em><\/strong> (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:<\/p>\n<\/div>\n<div data-lw-block-type=\"code\" data-lw-block-attributes=\"\">\n<pre class=\"wp-block-code\"><code>rm database_backup.sql\r\nrm website_backup.tar.gz<\/code><\/pre>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Remember to insert the actual file names of your backup files instead of using the placeholders shown above. Be cautious while using the <strong><em>rm<\/em><\/strong> command, as it permanently deletes files.<\/p>\n<\/div>\n<div data-lw-block-type=\"heading\" data-lw-block-attributes=\"{&quot;level&quot;:3}\">\n<h3 id=\"h-7-6-verify-the-deletion-of-all-backup-files\" class=\"Heading__SHeading-sc-o0nhd6-0\">7.6. Verify the deletion of all backup files<\/h3>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">Check that all files have been deleted as expected by listing the directory&#8217;s contents again using the <strong><em>ls<\/em><\/strong> command:<\/p>\n<\/div>\n<div data-lw-block-type=\"code\" data-lw-block-attributes=\"\">\n<pre class=\"wp-block-code\"><code>ls<\/code><\/pre>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">The deletion was successful if the directory is empty or no longer contains the backup files.<\/p>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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.<\/p>\n<\/div>\n<div data-lw-block-type=\"paragraph\" data-lw-block-attributes=\"\">\n<p class=\"Paragraph__SParagraph-sc-1p2ggqg-0\">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.<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-344","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts\/344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/comments?post=344"}],"version-history":[{"count":4,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts\/344\/revisions"}],"predecessor-version":[{"id":348,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts\/344\/revisions\/348"}],"wp:attachment":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/media?parent=344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/categories?post=344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/tags?post=344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}