Linux automatic backup

Source: Internet
Author: User
Tags ssh server rsync options

1. Tools used: rsync and ssh

2. features:

L check the original file and copy only the changed data blocks

L use ssh to encrypt data

L pre-transmission compression allowed

L automatically remove data from the target system when removing data from the source system

L allows you to set the data transmission speed of the WAN connection

L ability to copy Device Files

3. Simple backup

Figure 1: Backup

4. the Ssh server and client are set to implement automatic two-way authentication. We use the public key authentication. Here we use root to connect to the server. First, we need to change the ssh service configuration file/etc/ssh/sshd_config of the ssh server.

For example, remove the comment in the ellipse:

Figure 2

Then restart the service: # service sshd restart.

Generate a key pair for the root user at the Customer Service end:

# Ssh-keygen-t rsa

As shown in 3, The id_rsa and id_rsa.pub files will be generated under the. ssh/directory in the home directory. The first one is the private key, and the other one is the public key.

Figure 3

Copy the content of the public key id_rsa.pub to the/root/. ssh/authorized. keys file of the ssh server.

In this way, the server can use the public key to authenticate the root user. The client authenticates the server by automatically downloading the public key from the server during the first connection and placing it in ~ /. Ssh/known_hosts.

Last step: run # ssh-add command

Then test:

Enter:

# Ssh cluster2 hostname

Command. If the command succeeds, the hostname running result is directly output without a password prompt.

5. Configure rsync:

Create a test directory on the ssh client of the rsync master server:

# Mkdir/www

# Echo "this is a rsync test">/www/index.html

Run the rsync command:

# Rsync-v-a-z-e ssh -- delete/www/cluster2:/www

-V: Show operation information

-Files and directories under directory

-Z Compression

-E ssh transmission through ssh

/Www/source directory. Note that the backup destination is after the end of "/". For details about rsync options, refer to the online documentation to "pull" remote files to a local directory, you only need to switch the source and target paths.

6. The rest is through the cron job, and the backup is copied regularly. As follows:

# Crontab-e

30 * rsync-v-a-z-e ssh -- delete/www/cluster2:/www>/dev/null 2> & 1

In this way, automatic synchronization is performed every 30 minutes.

  1. Backup methods for Linux operating systems
  2. How small and medium enterprises choose Linux backup tools
  3. Backup and restoration skills for Linux servers

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.