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

Source: Internet
Author: User
Tags scp command ssh port


Linux Server Database (MySQL, ORACLE) simple remote backup solution Linux Server MySQL database simple remote backup solution www.2cto.com first simple: 1. execute scripts 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 where 195 is the ssh port number. If it is the default 22, you can omit-P 22. ------------------------------------------------------------------- Www.2cto.com now needs to write a sh script and set the sh script content in the scheduled task as follows: [java] #! /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" sh file do not forget to use chmod + x backup. sh to grant the executable permission. If we store the sh file in the opt directory, We need to configure the scheduled task editing file: vi/etc/crontab set to execute 30 04 *** root/bin/sh/opt/db/backup-database.sh every morning at half past four can use the command: cat/var/log/cron: After the execution log of the scheduled task is processed as above, the server automatically backs up the database and uploads it to a remote server. However, the problem still needs to be solved, that is, the scp command does not need a password. For specific configuration methods, refer: http://www.bkjia.com/os/201212/175290.html The following describes the differences between oracle and mysql. Generally, oracle backup can be performed only when su-oracle is switched to the oracle user. The following describes how to perform operations directly under the root user. In particular, some operations require the root user (for example, the password-less scp operation, here I am just an example), and some operations require the oracle user (exp Export user ). Key command: su-oracle-c "/opt/expdatabase. sh "means that the root user does not need to switch to the oracle user, but directly uses the oracle user role to execute expdatabase. sh file. Www.2cto.com we need to call the expdatabase. sh file in the sh file under root. The shell script is as follows: 1. Master sh script, and root executes [java] #! /Bin/sh filename = 'date' + % Y % m % d-% H % M % s' filename = "$ {filename} bak. dmp "su-oracle-c"/u01/oradata/bak/expdatabase. sh $ {filename} "scp-P 195/u01/oradata/bak/$ {filename} root@124.207.35.132: /bak/202.102.41.35 echo "Execution completed" 2. sh script expdatabase to be executed by the oracle user role. sh [java] #! /Bin/sh # Enter oracle home cd/u01/oracle # Load oracle user environment variables .. /. bash_profile exp user/password @ clmt file =/u01/oradata/bak/$1 full = y

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.