Back up the entire website with SSH Command Line
Backing up an entire website or blog can be a difficult and complicated process, requiring a lot of software, support tools, administrators with many skills and experiences, or support. directly from the hosting provider. But in fact, sometimes you will not need these factors. If you have SSH rights to access the host (minimum requirement is 1 virtual private network model - Virtual Private Server ), then things will become much simpler, you can backup, restore, move transfer . or perform other operations with the entire website with only a few commands.
So what is SSH Command Line?
In other words, SSH allows you to 'talk' directly to the web server. There is no concept of interface, function control buttons . all are done via the basic command line. Maybe this is a huge obstacle for many people, but in return, the absolute power, extremely fast working speed with high flexibility, integration of many automated mechanisms . then SSH Command Line becomes an indispensable tool once you've mastered it.
But in fact, most shared hosting packages do not provide SSH access to the user's account. If you are using GoDaddy's service, please refer to this process here. To login via SSH, open the Terminal application in OS X and type the following command:
ssh username@yourdomain.com
The system will ask the user to enter the password, if you have never used SSH before, it will be surprising that when you type the password, the screen does not display anything. No need to worry, because that feature is used to ensure system safety. After logging in, all you see is just the command line, similar to the following:
-bash-$ 3.2
It means that everything is stable. Next, we will learn more about other basic syntaxes. To list the current directory and file list, type the command:
ls
If you want to change the directory:
cd directoryname
In this case, we will move to the httpdocs directory - the root of the entire website, using the following command:
Backup database:
In fact, this can be considered as a process of backing up all the important files of the website. The first is the 3 most important information of the entire database, found in the wp-config.php file (for WordPress):
- Database name
- Database account
- Password
When using this command syntax, remember to replace the above information with the actual system, including the username, table name, backup file . respectively:
mysqldump --add-drop-table -u username -p tablename> backupfilename.sql
Press Enter, enter the password and the process will automatically proceed. Remember to use the ls command to check if the generated files are correct with the request.
Data backup:
After the above step, the entire database has been backed up into a single sql file on the server, followed by the process of backing up all data into a single compressed file, in case the risk occurs.
tar -vcf yourbackupfilename.tar.
Replace yourbackupfilename with the backup file name according to your wishes. At this command, Tar is a popular compression file format in Linux, similar to zip but much more efficient, and -vcf is another system option, with the function of creating compressed files and listing lists. The book is in progress, followed by the name of the archive. Finally, a dot to ask the system to back up everything, we can use * instead, but sometimes ignore hidden files like .htaccess - which is very important to WordPress.
After finishing the process, we will have a single .tar archive file, all you need to do at this time is to log in via FTP and download the file to your computer.
Restore everything:
Assuming that the worst case scenario occurs, you lose all of the website's data, all that remains is the backup file of the above process. And now the thing to do right now is restore the website's activity. First, log in via FTP and upload the backup file to the server, and remember to move the most recent backup file out of the root directory and proceed with it.
Extract the backup file directly on the server:
tar -vxf yourbackupfilename.tar
The difference here compared to the above statement is the -vxf syntax, which means extracting that * .tar file. The important point to note is that in this step, create a completely empty database with the same account name and password as the previous database, then type the command:
mysql -u username -p tablename> databasebackupfilename.sql
Very simple and easy, if everything is set up according to the requirements of the system, the backup process will be completed quickly and you will no longer have to struggle as before. In the next lesson, we will learn and implement this process automation with the shell script and CRON statements. Good luck!
You should read it
- Instructions for managing programs in Ubuntu via the command line
- What to back up on a Linux Home Server system?
- Adjust admin section of WordPress
- How to recover the content entered on the website
- What is technical SEO?
- How to assign admin rights to users in Ubuntu
- Install WordPress directly on the CPanel website
- Command line parameter in C
May be interested
- 12 best command line emulators for Windowsnowadays, users can get a shell inside windows 10, but many still prefer configurable command line emulators. therefore, this article will introduce to you five of the best command line emulator software for windows 10.
- How to download the entire website for offline readingalthough wifi is everywhere today, sometimes you will go to places where there is no wifi. for example, if you join a 12-hour international flight, downloading the entire site can be a great alternative to e-books, audio books, podcasts and movies. but how do you download a website? it's easier than you think! here are four tools that allow you to do that.
- 12 things Linux is easier to do in the command line than graphical softwaregraphical user interfaces (guis) were invented to make life easier for computer users, so it's very common to use them to perform most everyday tasks.
- How to copy (and paste) files and folders from the Linux command linecopying and pasting files is one of the most basic things you can do on your computer. on linux, you have several options to accomplish this.
- How to use Command Prompt, how to use cmd on Windowshidden deep within windows is a command line world that few people know about. in this article, we will show you how to resolve errors and make your computer more secure using the cmd command line tool.
- The basics of Cisco Switch Management - Part 1in the command-line interface cli (command-line interface) you can perform any type of configuration. so you can use the ios command line interface.
- How to Open a Command Line Program on Windowstipsmake today will show you how to open the command prompt command line window on windows pc. you can open command prompt from the start menu or any folder in file explorer. besides, the windows run feature is also an option.
- How to use the command history function in Command Promptcommand prompt is an extremely familiar command for anyone using windows operating system. besides, a lot of current software also supports the command line to perform actions on the command prompt window, instead of on the screen.
- Doskey command in Windowsthe doskey command calls doskey.exe (which reminds of previously entered command lines), modifies the command line and creates macros.
- The dd command in Linux, How to use the dd commanddd is a command line utility for unix-like and unix operating systems, with the main purpose of converting and copying files.