Use rsync in Linux to automate Web site backups (incremental backups)

Source: Internet
Author: User
Tags ssh rsync


First, we assume that the server on which the site is located is a server and that the backup server is a B server. The way to install rsync is not to say, Linux directly yum/apt-get install rsync can be

1. Create a public key and key on Server A with the Ssh-key-gen command (for password-free login to B server)

SSH-KEYGEN-T RSA

2. Run the Ssh-copy-id command on a server to copy the public key to the B server (. ssh/authorized_key)

IP of ssh-copy-id-i ~/.ssh/id_rsa.pub root@b Server

The password for the B server needs to be entered during

If the error appears as follows

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ warning:remote HOST Identification has changed! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT is POSSIBLE This SOMEONE is doing something nasty!
Someone could is eavesdropping on your right now (Man-in-the-middle attack)!
It is also possible the RSA host key has just been changed.
The fingerprint for the "RSA key sent by" The remote host is
xxxxxxxx
Please contact your system administrator.
Add correct host key in/home/conbar/.ssh/known_hosts to get rid of the.
Offending key In/home/conbar/.ssh/known_hosts:10
RSA host key for XXXXXX has changed and your have requested strict.
Host Key verification failed.

Run the following command under a server

IP of ssh-keygen-r b server

3. Try to log on to Server B on Server A

SSH b server ip

If it works, it'll be fine.

The 4.A server establishes a backup script (the example of this article is the creation of a backup.sh file under/root):

Example 1 (package and then sync):

#!/bin/bash
echo "Now packing your database ..."
Mysqldump-uroot-p Database Password database name > Backup.sql
echo "Now your files ..."
Tar zcvfp backup.tar.gz web site directory (e.g./home/wwwroot)
echo "rsync start ..."
echo "Database file is under rsync ..."
Rsync-avz-e "Ssh-o stricthostkeychecking=no-o userknownhostsfile=/dev/null"--progress/root/backup.sql B server Ip:/home /
echo "Now your files ..."
Rsync-avz-e "Ssh-o stricthostkeychecking=no-o userknownhostsfile=/dev/null"--progress/root/backup.tar.gz B server ip:/ home/
echo "complete!"

Example 2 (direct synchronization of the Web site directory for incremental Backups):

#!/bin/bash
echo "Now packing your database ..."
Mysqldump-uroot-p Database Password database name > Backup.sql
echo "rsync start ..."
echo "Database file is under rsync ..."
Rsync-avz-e "Ssh-o stricthostkeychecking=no-o userknownhostsfile=/dev/null"--progress/root/backup.sql B server Ip:/home /
echo "Now your files ..."
Rsync-avz-e "Ssh-o stricthostkeychecking=no-o userknownhostsfile=/dev/null"--progress/home/wwwroot B server ip:/home/
echo "complete!"

5. Increase running permissions for backup scripts

chmod +x backup.sh

Run SH backup.sh for backup attempts

6. Set crontab (CRONTAB-E command) for regular backups (every Tuesday, Thursday 4 o'clock in the morning to start the backup)

# m H Dom Mon Dow command
0 4 * * 1,4/bin/bash/root/backup.sh

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.