In linux, the Web server backup and recovery script can be used in both centos and freebsd, but the variable TAR in the script to be modified is the tar command path of the system. The script is as follows:
In linux, the Web server backup and recovery script can be used in both centos and freebsd, but the variable TAR in the script to be modified is the tar command path of the system. The script is as follows:
#! /Bin/sh cat <EOF + ------------------------------------------------------------------ + |== server backup and recovery script ==| ------------------ http://www.xmo.cc-------------------| + ----------------------- Clairelume release + EOF WEB_DIR =/data/www BACK_DIR =/data/www/webback TIME = 'date + % Y % m % d 'tar = "/usr/bin/ tar "TAR_BACK =" czf "TAR_RECOVERY =" xvzf "COLOR_CYAN =" \ 033 [36; 49; 1 m "COLOR_GREEN =" \ 033 [32; 49; 1 m "COLOR_RED =" \ 033 [31; 49; 1 m "COLOR_BACK =" \ 033 [39; 49; 0 m "echo-e" $ COLOR_CYAN backup environment information: $ COLOR_BACK "echo" + ---------------------------------------------------------- ---- + "Echo-e" $ COLOR_CYAN 1. program Directory: $ WEB_DIR $ COLOR_BACK "echo-e" $ COLOR_CYAN 2. backup Directory: $ BACK_DIR $ COLOR_BACK "echo-e" $ COLOR_CYAN 3. backup TIME: $ TIME $ COLOR_BACK "echo-e" $ COLOR_CYAN 4. backup file format: web_back _ 'date too many yymm1_d'.tar.gz $ COLOR_BACK "echo-e" $ COLOR_RED note: Directory parameters in shell, modify the corresponding directory $ COLOR_BACK "echo" + -------------------------------------------------------------------- + "if [! -D $ BACK_DIR]; then mkdir-p $ BACK_DIR fi while true; do echo-e "$ COLOR_CYAN Please select the operation (1 = backup, 2 = recovery, 3 | q | Q = quit, * = reselect) [1, 2, 3]: $ COLOR_BACK "read a case" $ a "in 1) echo-e "$ COLOR_CYAN: $ COLOR_BACK "echo" + -------------------------------------------- + "ls-l $ WEB_DIR | grep '^ d' | awk' {print $ NF} 'echo" + response + "echo-e" $ COLOR_CYAN: $ COLOR_BACK "Read B if [-d $ WEB_DIR/$ B]; then cd $ WEB_DIR $ TAR $ TAR_BACK $ BACK_DIR/"$ B" _ back _ 'date when policy?m=d'.tar.gz $ B/>/dev/null 2> & 1 echo-e "$ COLOR_GREEN $ TIME $ B backed up successfully! Select another operation $ COLOR_BACK "echo" $ TIME $ B. The backup is successful! $ TIME ">/var/log/web_back.log else echo-e" $ COLOR_RED: $ COLOR_BACK "read d if [-d $ WEB_DIR/$ d]; then cd $ WEB_DIR $ TAR $ TAR_BACK $ BACK_DIR/"$ d" _ back _ 'date when policy?m=d'.tar.gz $ d/>/dev/null 2> & 1 echo-e "$ COLOR_GREEN $ TIME $ d backup successful! Select another operation $ COLOR_BACK "echo" $ TIME $ d. The backup is successful! $ TIME ">/var/log/web_back.log else echo-e" $ COLOR_RED backup site name input error twice. exit the current backup and select! $ COLOR_BACK "echo" $ TIME backup site name input error twice, exit the current backup! ">>>/Var/log/web_back.log fi continue; 2) echo-e" $ COLOR_CYAN backup file of the current server: $ COLOR_BACK "echo" + response + "ls-l $ BACK_DIR | grep" tar.gz "| awk '{print $ NF} 'echo" + response + "echo-e" $ COLOR_CYAN select the recovery file to be restored: $ COLOR_BACK "read c if [-f $ BACK_DIR/$ c]; then cd $ WEB_DIR $ TAR $ TAR_RECOVERY $ BACK_DIR/$ c-C $ WEB_DIR/>/dev/n Ull 2> & 1 echo-e "$ COLOR_GREEN $ TIME $ c is restored successfully. please select another operation! $ COLOR_BACK "echo" $ TIME $ c success! ">>/Var/log/web_back.log else echo-e" $ COLOR_RED: The site does not exist to be restored. please enter the following again: $ COLOR_BACK "read f if [-f $ BACK_DIR/$ f]; then cd $ WEB_DIR $ TAR $ TAR_RECOVERY $ BACK_DIR/$ f-C $ WEB_DIR/>/dev/null 2> & 1 echo-e "$ COLOR_GREEN $ TIME $ f success, select another operation! $ COLOR_BACK "echo" $ TIME $ f success! ">/Var/log/web_back.log else echo-e" $ COLOR_RED restore file name input error twice, exit the current recovery selection! $ COLOR_BACK "echo" $ TIME indicates that an error occurred twice in restoring the file name. exit the current recovery option! ">>>/Var/log/web_back.log fi continue; 3 | Q | q) echo-e" $ COLOR_GREEN exits successfully! $ COLOR_BACK "exit; *) echo-e" $ COLOR_RED input error. please enter it again! $ COLOR_BACK "continue; esac exit 0 done