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= database password to back up the database name > "${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, more Crontab introduction here
The code is as follows |
Copy Code |
Crontab-e * * */bin/sh/root/backup/web_backup.sh |
3, problems that may be encountered:
The SCP Remote replication command in step 1 encounters a prompt to enter a password, which can result in unsuccessful replication if there is no password input. Through Baidu found the solution.
1, generate the key file in the ~/.ssh/directory on the VPS server:
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, the VPS server ~/.ssh/id_rsa.pub content appended to the X4100 server ~/.ssh/authorized_keys inside
This may not prompt you for a password entry when calling the SCP command.