Sometimes a website data is needed, but we cannot always view it. & nbsp; so we can automatically back up website data and send it to our ftp server (preferably for free www.godaddy.com application) to back up Website Data. Today, we wrote a shell script on VPS, use crontab to customize website data
Sometimes a website data is needed, but we cannot always view it.
Therefore, we can automatically back up website data and send it to our ftp server (preferably free www.godaddy.com application) to back up Website Data. Today, we wrote a shell script on VPS, use crontab to automatically back up website data. The following is the shell script I used (note: The shell script name is backup. sh: put it in the/root directory. the mysql installation directory is/usr/local/mysql, and the website root directory is/home/wwwroot/31sky.net, modify the shell script according to your actual situation ):
#! /Bin/bash
/Usr/local/mysql/bin/mysqldump-u mysql username-p mysql password mysql database name>/home/wwwroot/36pl.com/$ (date + % Y % m % d) -36pl. SQL
Cd/home/wwwroot/36pl.com
Tar-zcvf $ (date when policyymm1_d0000-36pl.com.tar.gz ./*
Echo "IP address of open ftp
User ftp username ftp password
Bin
Prompt off
Mput $ (date when policyuncmdemo-36pl.com.tar.gz
Printf ""
Close
Bye "| ftp-I-n
Rm-rf $ (date + % Y % m % d)-36pl. SQL $ (date 1_policy1_m1_d1_-36pl.com.tar.gz
Modify the backup. sh permission so that it has executable permissions.
Chmod + x backup. sh
Finally, set crontab:
Crontab-e
Add a line (backup starts at every day ):
10 00 ***/root/backup. sh
Note: In some cases, after crontab is set but it does not run, you can restart crontab:
Service crond restart