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.