Backup files in Linux with the tar compression command of SSH

Source: Internet
Author: User
Tags ssh

Now most of the virtual host has automatic backup function, but sometimes can not rely on the host is not, if the host is black, even backup files can not be restored, then cry miserably, so that people are inferior to rely on their own. Today 111cn.net teaches everybody how to give back to own website, here uses Hostgator this foreign space to say.

Backups are generally divided into two parts, one for file backups and the other for database backups. Here is how to back up the file, want to see database backup see: How to Back up the database via SSH mysqldump command


First of all, file backup bar, the general virtual host with a file management system, take Hostgator, there is a Files manager, although we can compress the folder through him, and then use FTP tools to achieve our local backup purposes, but if you have too many Web site files, Will cause the phenomenon of suspended animation. So 111cn.net is still not recommended to use cpanel inside the file management system to back up. This is about packing files with an SSH command.


First make sure your space is open SSH, if not please contact space to open this feature, and then through the Putty to connect our space. Enter a username password and Putty will open a window similar to the CMD command line. Then we use the TAR or ZIP commands to package our website folders.


to compress a specified folder by using SSH:


TAR compression command

The code is as follows Copy Code

TAR-CZVF 111cn.net.tar./111cn.net.net


111cn.net.tar is the compressed file name
./111cn.net.net is the destination folder that needs to be compressed


ZIP compression command

The code is as follows Copy Code

Zip-r 111cn.net.zip 111cn.net.net


111cn.net.tar is the compressed file name
./111cn.net.net is the destination folder that needs to be compressed


How to extract the compressed package with SSH:

The code is as follows Copy Code

Tar Decompression tar Compression pack command
Tar Xvfz 111cn.net.tar


Unzip decompression zip compression pack command
Unzip 111cn.net.zip


OK, at this time, your database has been backed up, directly with the FTP tool to drag to the local backup bar.


example, look at an ssh mysqldump command to back up the database

First make sure your space is open SSH, if not please contact space to open this feature, and then through the Putty to connect our space. Enter a username password and Putty will open a window similar to the CMD command line. Then we use the TAR or ZIP commands to package our website folders.


the process of backing up data:

The code is as follows Copy Code
Mysqldump-h mysql.forece.net-p mysql_dbname-u Mysql_dbuser >bak.sql

Here mysql.forece.net is your database server address, if your database does not have a domain name, then directly fill in localhost also can, Mysql_dbname is your database name, Mysql_dbuser is your database username, Bak.sql is the script file name of the database you backed up (you can use it to recover data in the future). Then enter, prompts you to input the database login password, enter the password after the return, Liunx enter the password is not back to show, so you just input, pay attention to not wrong on the line!


OK, at this time, your database has been backed up, directly with the FTP tool to drag to the local backup bar.


the process of importing (restoring) Data:
still in the previous SSH command line mode, enter the following command to enter the database:

The code is as follows Copy Code
Mysql-h mysql.forece.net-p mysql_dbname-u Mysql_dbuser

Then enter, prompts you to input the database login password, after entering the password, the carriage return will appear the MySQL operation prompt symbol, then enters the following command:

The code is as follows Copy Code


SOURCE Bak.sql


Note To confirm Bak.sql This file is in the current directory Oh, no problem then click Enter, this is the beginning of recovery data, patience wait for a while ...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.