Simple remote backup solution for Linux Server databases (MySQL and Oracle)

Source: Internet
Author: User
Tags scp command ssh port
Simple remote backup solution for Linux Server databases (MySQL and Oracle)

Simple remote backup solution for Linux Server databases (MySQL and Oracle)

Simple remote backup solution for MySQL Databases on Linux servers

First, let's briefly describe:

1. Execute the script to export the database.

Mysqldump-h127.0.0.1-P3306-uroot-ppassword dbname>/bak/db/backup. SQL

2. Use scp to transmit exported database files to other servers. Generally, remote backup and disaster tolerance are performed.

Scp-P 195/bak/db/backup. SQL root@xxx.xxx.xxx.xxx:/bak

195 indicates the ssh port number. If it is 22 by default,-P 22 can be omitted.

Bytes -----------------------------------------------------------------------------------------------------------------

Now you need to write an sh script and set it to a scheduled task.

THE sh script content is as follows:

#! /Bin/sh

Filename = 'date' + % Y % m % d-% H % M % s''
Filename = "$ {filename} bak. SQL"

Mysqldump-h127.0.0.1-P3306-uroot-ppassword dbname>/bak/db/$ {filename}

Scp-P 195/bak/db/$ {filename} root@xxx.xxx.xxx.xxx:/bak

Echo "success"

Do not forget to use chmod + x backup. sh to grant executable permissions to sh files.

If we store the sh file in the opt directory, We need to configure the scheduled task.

Edit file: vi/etc/crontab is set to run at half past four every day

30 04 *** root/bin/sh/opt/db/backup-database.sh

Run the command cat/var/log/cron to view the execution log of the scheduled task.

After the above processing, the server will automatically back up the database and upload it to the remote server. However, there is still a problem to be solved, that is, the scp command does not need a password.

For specific configuration methods, refer to my other article:

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.