Implementation of automatic backup database for VPS in Linux

Source: Internet
Author: User
Tags mkdir ssh vps scp command vps server
The code is as follows Copy Code

#!/bin/bash
D= "/root/backup"
t= ' Date +%y%m%d '
if [!-d ' ${d}/${t} ']; Then
/bin/mkdir "${d}/${t}"
Fi
/usr/local/mysql/bin/mysqldump--host=localhost--user=root--password= database password to back up the database name > "${d}/${t}/${t}.sql"
CD ${d}
/bin/tar-czf "${d}/${t}.tar.gz" "${t}"
/USR/BIN/SCP "${d}/${t}.tar.gz" kuco@x4100.unix-center.net:~/web_backup/studyday.net


2, set Crontab, more Crontab introduction here

The code is as follows Copy Code

Crontab-e
* * */bin/sh/root/backup/web_backup.sh

3, problems that may be encountered:

The SCP Remote replication command in step 1 encounters a prompt to enter a password, which can result in unsuccessful replication if there is no password input. Through Baidu found the solution.

1, generate the key file in the ~/.ssh/directory on the VPS server:

The code is as follows Copy Code
Mkdir-p ~/.ssh
Ssh-keygen-t rsa-p ""-F ~/.ssh/id_rsa

2, configure on the X4100 server:

The code is as follows Copy Code
Mkdir-p ~/.ssh
Touch ~/.ssh/authorized_keys

3, the VPS server ~/.ssh/id_rsa.pub content appended to the X4100 server ~/.ssh/authorized_keys inside

This may not prompt you for a password entry when calling the SCP command.

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.