Linux Server Data Backup

Source: Internet
Author: User

Purpose: Periodically compress the data on server A and Server B to the C server

1. Choose Password-Free login

1.1 Execute under the root directory on A/b server, respectively:

SSH-KEYGEN-T RSA

--and then keep the ENTER key. Finally, the. ssh file is generated in the ~ directory, with three files in it.

Authorized_keys  Id_rsa  id_rsa.pub

Authorized_keys: The public key that stores the remote password-free login, which records the public key of multiple machines mainly through this file.

ID_RSA: Generated private key file

Id_rsa.pub: Generated Public key file

Know_hosts: List of known host public keys

which

Id_rsa.pub for the generated public key, copy it to the C server, authorized_keys,know_hosts on the new server without
1.2 respectively, the id_rsa.pub on a, B, through the SCP to C
A:
Scp-p-p< port > ~/.ssh/id_rsa.pub [Email protected]<remoteip>:/root/.ssh/a_rsa.pub

B:
Scp-p-p< port > ~/.ssh/id_rsa.pub [Email protected]<remoteip>:/root/.ssh/b_rsa.pub

The--SCP command,-p for the specified port, is not specified as the default 22 port.

Then append the sent file to Authorized_keys on the C server:

// Append Acat/root/.ssh/a_rsa.pub >>/root/.ssh/// append b

Verify success:

ssh-p< Ports > <remote>

To be able to go in means success.

2 Implementation of Backup scripts

2.1

Compress the file before backing it up, generate MD5, MD5 verify the C server, delete the corresponding md5,gz on server A after the file is consistent, and file 20 days ago

#!/bin/bash######### Cache ########### #local Filepathlocalpath=$1#topathtopath=$2#datedate=$ (Date +%y%m%d) FileName=*. Log#statusmdstatus=1#md5 localfile#md5sum ${localpath}${filename}> "${date}". MD5#CDCD"${localpath}"#tar localfiletar zcf ${filename}"-"${date}.tar.gz ${filename} #md5 local tarmd5sum ${filename}"-" ${date}.tar.gz > "${date}". MD5#SCPSCP-p1022 ${filename} "-" ${date}.tar.gz [email protected]<remoteip>: ${TOPATH}SCP-p1022 ${date}.md5 [Email protected]<remoteip>: ${topath} #sshmdstatus= ' SSH [email protected]<remoteip>-P 1022-TQ <<REMOTESSHCD"${topath}"md5sum-C--status ${date}.md5 echo $?exitremotessh ' #deleteif["${mdstatus}"-eq 0]; then echo"Success"Find ${localpath}-mtime +20-name "*.log"-exec RM-RF {} \; RM-RF ${localpath}*. GZ RM-RF ${localparh}*. Md5fi

3. Timed Task Execution Script

Crontab-e

Time-sharing week [order]

* * * * * * [Commond]

0 8 * * * [Script path]

Complete

Linux Server Data Backup

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.