Implementation of VPS automatic database backup in linux

Source: Internet
Author: User

This is my automatic backup database SHELL script. It will run on the VPS server, export the database, compress it into a package, and then back up the compressed package to another server (x4100) using the scp command.

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 = Name of the database whose password is to be backed up> "$ {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. For more information about crontab, see here.

The Code is as follows: Copy code

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

3. Possible problems:

In STEP 1, when the scp remote Copy command is run, a prompt will be prompted for entering the password. If no password is entered, the copy will fail. The solution is found through Baidu.

1. On the VPS server ~ /. Ssh/directory to generate the key file:

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. Change ~ /. Ssh/id_rsa.pub content appended to the x4100 server ~ /. Ssh/authorized_keys

In this way, no password prompt is prompted when the scp command is called.

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.