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: