SH Backup Script


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/bin/bash
  2. #
  3. # Version 0.04 - JF Nutbroek 2008
  4. #
  5.  
  6. # Various Paths
  7.  
  8. SCRIPT="/root/tools"
  9. HTFOLDER="/opt/lampp/htdocs"
  10. MYSQL="/opt/lampp/bin/mysql"
  11. MYSQLDUMP="/opt/lampp/bin/mysqldump"
  12. BACKUPLOC="/backups"
  13.  
  14. # temporary file
  15. TEMP=/tmp/answer$$
  16.  
  17. # set default values
  18. MIRROR="" ; USERNAME="root" ; PASSWORD=""
  19. EXCLUDEDB="" ; EXCLUDEHTDOCS="" ; FTP="yes" ; FTPDUMP="no"
  20. FTPUSERNAME="anonymous" ; FTPPASSWORD="root@localhost" ; FTPIP=""
  21. FTPDIR="/backups" ; LASTWEEK="yes" ; SAVE="no" ; ONEDAY="no"
  22.  
  23. # clean up and exit
  24. clean_up() {
  25. setterm -background black
  26. clear
  27. rm -f $TEMP >/dev/null 2>&1
  28. exit
  29. }
  30.  
  31. # Note: The functions startftp, stopftp, enable and disable
  32. # need to be modified according to the Linux system in use
  33.  
  34. # Code starts here
  35.  
  36. if [ -f "$SCRIPT/.backup" ]; then
  37. . $SCRIPT/.backup
  38. fi
  39.  
  40. startftp() {
  41. SERVICE="vsftpd"
  42. RUNNING=`ps ax | grep -v grep | grep $SERVICE`
  43. if [ "$RUNNING" = "" ]; then
  44. sh /etc/rc.d/rc.vsftpd start >/dev/null 2>&1
  45. fi
  46. }
  47.  
  48. stopftp() {
  49. SERVICE="vsftpd"
  50. RUNNING=`ps ax | grep -v grep | grep $SERVICE`
  51. if [ ! "$RUNNING" = "" ]; then
  52. sh /etc/rc.d/rc.vsftpd stop >/dev/null 2>&1
  53. fi
  54. }
  55.  
  56. disable() {
  57. if [ -f "/etc/cron.daily/startbackup.sh" ]; then
  58. rm /etc/cron.daily/startbackup.sh
  59. fi
  60. echo "Backup has been disabled"
  61. }
  62.  
  63. enable() {
  64. echo "#!/bin/bash" > /etc/cron.daily/startbackup.sh
  65. echo "sh $SCRIPT/backup.sh start" >> /etc/cron.daily/startbackup.sh
  66. chmod 0755 /etc/cron.daily/startbackup.sh
  67. echo "Backup has been enabled"
  68. }
  69.  
  70. check() {
  71. OUT=$?
  72. if [ ! $OUT -eq 0 ]; then
  73. echo "Error! - Please check your configuration"
  74. exit 2
  75. fi
  76. }
  77.  
  78. start() {
  79.  
  80. # Get todays date
  81. DAYOFWEEK=`date +%a`
  82. TODAY=`date +%F%t%R`
  83.  
  84. # Check if configurationfile is available
  85. if [ ! -f "$SCRIPT/.backup" ]; then
  86. echo "Please configure the backup first!"
  87. exit 2
  88. fi
  89.  
  90. # Stop FTP service
  91. if [ "$FTP" = "yes" ]; then
  92. stopftp
  93. fi
  94.  
  95. # Create required directories
  96. if [ ! -d $BACKUPLOC ]; then
  97. mkdir $BACKUPLOC
  98. fi
  99. cd $BACKUPLOC
  100. check
  101. if [ "$ONEDAY" = "yes" ]; then
  102. rm -r * >/dev/null 2>&1
  103. fi
  104. if [ ! -d daily ]; then
  105. mkdir daily
  106. check
  107. fi
  108. if [ "$LASTWEEK" = "yes" ]; then
  109. if [ ! -d lastweek ]; then
  110. mkdir lastweek
  111. check
  112. fi
  113. fi
  114. cd daily
  115. check
  116. if [ ! -d $DAYOFWEEK ]; then
  117. mkdir $DAYOFWEEK
  118. check
  119. fi
  120.  
  121. # Redirect I/O
  122. if [ -f $BACKUPLOC/daily/$DAYOFWEEK/.logfile ]; then
  123. rm $BACKUPLOC/daily/$DAYOFWEEK/.logfile
  124. else
  125. touch $BACKUPLOC/daily/$DAYOFWEEK/.logfile
  126. fi
  127. exec 6>&1
  128. exec > $BACKUPLOC/daily/$DAYOFWEEK/.logfile
  129. exec 7>&2
  130. exec 2> $BACKUPLOC/daily/$DAYOFWEEK/.logfile
  131.  
  132. # Start backup of HTDOCS directory
  133. cd $HTFOLDER
  134. check
  135. HTDOCSNAMES="`find -type d -maxdepth 1 | sed 's/\.//g;' | sed 's/\///g;' | sed -e '1,1d'`"
  136. for exclude in $EXCLUDEHTDOCS
  137. do
  138. HTDOCSNAMES=`echo $HTDOCSNAMES | sed "s/\b$exclude\b//g"`
  139. done
  140. echo "$TODAY" > $BACKUPLOC/daily/$DAYOFWEEK/.mailmessage
  141. echo "" >> $BACKUPLOC/daily/$DAYOFWEEK/.mailmessage
  142. rm $BACKUPLOC/daily/$DAYOFWEEK/htdocs_*.tar.gz >/dev/null 2>&1
  143. for include in $HTDOCSNAMES
  144. do
  145. HT="`echo $include | sed 's/%/ /g'`"
  146. tar cfz htdocs_${HT}_$DAYOFWEEK.tar.gz $HT
  147. mv htdocs_${HT}_$DAYOFWEEK.tar.gz $BACKUPLOC/daily/$DAYOFWEEK/
  148. done
  149. # Backup all htdocs root files
  150. tar cfz htdocs_rootfiles_$DAYOFWEEK.tar.gz *.*
  151. mv htdocs_rootfiles_$DAYOFWEEK.tar.gz $BACKUPLOC/daily/$DAYOFWEEK/
  152.  
  153. # Start backup of MySQL directory
  154. cd $BACKUPLOC/daily/$DAYOFWEEK/
  155. DBNAMES="`$MYSQL --user=$USERNAME --password=$PASSWORD --host=localhost --batch --skip-column-names -e "show databases" | sed 's/ /%/g'`"
  156. for exclude in $EXCLUDEDB
  157. do
  158. DBNAMES=`echo $DBNAMES | sed "s/\b$exclude\b//g"`
  159. done
  160. rm mysql_*.gz >/dev/null 2>&1
  161. for include in $DBNAMES
  162. do
  163. DB="`echo $include | sed 's/%/ /g'`"
  164. $MYSQLDUMP --user=$USERNAME --password=$PASSWORD --host=localhost --quote-names --opt $DB > mysql_${DB}_$DAYOFWEEK.sql
  165. gzip -f mysql_${DB}_$DAYOFWEEK.sql
  166. done
  167.  
  168. # Start FTP
  169. if [ "$FTP" = "yes" ]; then
  170. startftp
  171. fi
  172.  
  173. echo "Created the following archives:" >> .mailmessage
  174. echo "" >> .mailmessage
  175. du -hl *.gz >> .mailmessage
  176. echo "" >> .mailmessage
  177.  
  178. # Rotate the backups to the lastweek directory
  179. DAYNUMBER=`date +%u`
  180. if [ "$LASTWEEK" = "yes" ]; then
  181. if [ "$DAYNUMBER" = "7" ]; then
  182. cp -rf $BACKUPLOC/daily $BACKUPLOC/lastweek/
  183. echo "- Rotated last weeks backups" >> .mailmessage
  184. echo "" >> .mailmessage
  185. fi
  186. fi
  187.  
  188. # Create a mirror copy on another drive
  189. if [ ! "$MIRROR" = "" ]; then
  190. rsync -av $BACKUPLOC $MIRROR >/dev/null 2>&1
  191. echo "- Created mirror to $MIRROR" >> .mailmessage
  192. echo "" >> .mailmessage
  193. fi
  194.  
  195. # Create FTP dump
  196. if [ "$FTPDUMP" = "yes" ]; then
  197. TODAY=`date +%R`
  198. echo "- Starting FTP dump at $TODAY" >> .mailmessage
  199. /usr/local/bin/ncftpput -u "$FTPUSERNAME" -p "$FTPPASSWORD" -R -V "$FTPIP" "$FTPDIR" "$BACKUPLOC/daily/$DAYOFWEEK/"
  200. TODAY=`date +%R`
  201. echo "- Ended FTP dump on $TODAY" >> .mailmessage
  202. echo "" >> .mailmessage
  203. fi
  204.  
  205. # Add filesystem details to the log and send it by email
  206. echo "Current filesystem usage:" >> .mailmessage
  207. echo "" >> .mailmessage
  208. df -h >> .mailmessage
  209. echo "" >> .mailmessage
  210.  
  211. # Add logfile
  212. if [ -s .logfile ]; then
  213. echo "Error messages:" >> .mailmessage
  214. cat .logfile >> .mailmessage
  215. else
  216. echo "No error messages" >> .mailmessage
  217. fi
  218. echo "" >> .mailmessage
  219.  
  220. # Clean up I/O redirection
  221. exec 1>&6 6>&-
  222. exec 1>&7 7>&-
  223.  
  224. TODAY=`date +%F%t%R`
  225. echo "$TODAY" >> .mailmessage
  226. if [ ! "$EMAILADDRESS" = "" ]; then
  227. cat .mailmessage | mail -s "Backup report" $EMAILADDRESS
  228. fi
  229.  
  230. }
  231.  
  232. restore() {
  233.  
  234. # Restore MySQL or HTDOCS
  235. echo "##### WARNING - RESTORING OLD ARCHIVE #####"
  236. echo ""
  237. PS3='Please make your selection: '
  238. select type in "Restore MySQL Database" "Restore HTDOCS folder" ; do
  239. break
  240. done
  241. echo ""
  242.  
  243. # Restore MySQL
  244. if [ "$type" = "Restore MySQL Database" ]; then
  245. echo "Restoring MySQL Database"
  246. echo ""
  247. DBNAMES="`$MYSQL --user=$USERNAME --password=$PASSWORD --host=localhost --batch --skip-column-names -e "show databases" | sed 's/ /%/g'`"
  248. for exclude in $EXCLUDEDB
  249. do
  250. DBNAMES=`echo $DBNAMES | sed "s/\b$exclude\b//g"`
  251. done
  252. PS3='Please select the database you would like to restore:'
  253. select DB in $DBNAMES "Not listed" ; do
  254. break
  255. done
  256. echo ""
  257. if [ "$DB" = "Not listed" ]; then
  258. echo "Please enter the database name"
  259. read DB
  260. echo ""
  261. fi
  262. archives="`find $BACKUPLOC -iname mysql_${DB}*.gz`"
  263. PS3='Please select the backup to restore: '
  264. select archive in $archives "Cancel" ; do
  265. break
  266. done
  267. echo ""
  268. if [ "$archive" = "Cancel" ]; then
  269. echo ""
  270. echo "Restore database has been cancelled"
  271. exit 0
  272. fi
  273. echo "Restore: $archive (yes or no)?"
  274. read answer
  275. if [ "$answer" = "yes" ]; then
  276. gunzip $archive
  277. archive="`echo $archive | sed 's/\.gz//g'`"
  278. $MYSQL --user=$USERNAME --pass=$PASSWORD --host=localhost $DB < $archive
  279. gzip -f $archive
  280. echo ""
  281. echo "Database restored"
  282. else
  283. echo ""
  284. echo "Restore database has been cancelled"
  285. fi
  286. fi
  287.  
  288. # Restore HTDOCS
  289. if [ "$type" = "Restore HTDOCS archive" ]; then
  290. echo "Restoring HTDOCS archive"
  291. echo ""
  292. cd $HTFOLDER
  293. HTDOCSNAMES="`find -type d -maxdepth 1 | sed 's/\.//g;' | sed 's/\///g;' | sed -e '1,1d'`"
  294. for exclude in $EXCLUDEHTDOCS
  295. do
  296. HTDOCSNAMES=`echo $HTDOCSNAMES | sed "s/\b$exclude\b//g"`
  297. done
  298. PS3='Please select the HTDOCS archive you would like to restore:'
  299. select HT in $HTDOCSNAMES "Not listed" ; do
  300. break
  301. done
  302. echo ""
  303. if [ "$HT" = "Not listed" ]; then
  304. echo "Please enter the HTDOCS archive name"
  305. read HT
  306. echo ""
  307. fi
  308. archives="`find $BACKUPLOC -iname htdocs_${HT}*.gz`"
  309. PS3='Please select the backup to restore: '
  310. select archive in $archives "Cancel" ; do
  311. break
  312. done
  313. echo ""
  314. if [ "$archive" = "Cancel" ]; then
  315. echo ""
  316. echo "Restore HTDOCS archive has been cancelled"
  317. exit 0
  318. fi
  319. echo "Restore: $archive (yes or no)?"
  320. read answer
  321. if [ "$answer" = "yes" ]; then
  322. cp $archive $HTFOLDER/
  323. archive="`basename $archive`"
  324. gunzip $archive
  325. archive="`echo $archive | sed 's/\.gz//g'`"
  326. tar -xf $archive
  327. rm $archive
  328. echo ""
  329. echo "HTDOCS archive restored"
  330. else
  331. echo ""
  332. echo "HTDOCS restore cancelled"
  333. fi
  334. fi
  335. }
  336.  
  337. main_menu() {
  338. dialog \
  339. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  340. --title "Configure Backup" \
  341. --menu "Select a function:" 0 0 0 \
  342. 1 "EDIT backup configuration" \
  343. 2 "SHOW backup configuration" \
  344. 3 "SAVE backup configuration" \
  345. 4 "ENABLE daily backup" \
  346. 5 "DISABLE daily backup" \
  347. 6 "TEST backup now!" \
  348. 7 "EXIT" 2>$TEMP
  349.  
  350. if [ "$?" != "0" ] ; then clean_up ; fi
  351. choice=`cat $TEMP`
  352. case $choice in
  353. 1) edit_backup;;
  354. 2) view_backup;;
  355. 3) save;;
  356. 4)
  357. if [ "$SAVE" = "yes" ]; then
  358. save
  359. enable
  360. else
  361. enable
  362. fi
  363. dialog \
  364. --sleep 1 \
  365. --infobox "Enabling.." 3 30
  366. ;;
  367. 5)
  368. disable
  369. dialog \
  370. --sleep 1 \
  371. --infobox "Disabling.." 3 30
  372. ;;
  373. 6)
  374. dialog \
  375. --sleep 1 \
  376. --infobox "Starting backup.." 3 30
  377. start
  378. if [ "$EMAILADDRESS" = "" ]; then
  379. dialog \
  380. --sleep 3 \
  381. --infobox "Completed!\nCheck $BACKUPLOC for the result" 5 45
  382. else
  383. dialog \
  384. --sleep 3 \
  385. --infobox "Completed!\nCheck your email for the result" 5 45
  386. fi
  387. ;;
  388. 7) clean_up;;
  389. esac
  390. main_menu
  391. }
  392.  
  393. save() {
  394. dialog \
  395. --sleep 1 \
  396. --infobox "Saving..." 3 13
  397. echo "#!/bin/bash" > $SCRIPT/.backup
  398. echo "# Backup configuration file" >> $SCRIPT/.backup
  399. echo "BACKUPLOC=\"$BACKUPLOC\"" >> $SCRIPT/.backup
  400. echo "MIRROR=\"$MIRROR\"" >> $SCRIPT/.backup
  401. echo "USERNAME=\"$USERNAME\"" >> $SCRIPT/.backup
  402. echo "PASSWORD=\"$PASSWORD\"" >> $SCRIPT/.backup
  403. echo "EXCLUDEDB=\"$EXCLUDEDB\"" >> $SCRIPT/.backup
  404. echo "EXCLUDEHTDOCS=\"$EXCLUDEHTDOCS\"" >> $SCRIPT/.backup
  405. echo "FTP=\"$FTP\"" >> $SCRIPT/.backup
  406. echo "FTPDUMP=\"$FTPDUMP\"" >> $SCRIPT/.backup
  407. echo "FTPUSERNAME=\"$FTPUSERNAME\"" >> $SCRIPT/.backup
  408. echo "FTPPASSWORD=\"$FTPPASSWORD\"" >> $SCRIPT/.backup
  409. echo "FTPIP=\"$FTPIP\"" >> $SCRIPT/.backup
  410. echo "FTPDIR=\"$FTPDIR\"" >> $SCRIPT/.backup
  411. echo "LASTWEEK=\"$LASTWEEK\"" >> $SCRIPT/.backup
  412. echo "ONEDAY=\"$ONEDAY\"" >> $SCRIPT/.backup
  413. echo "EMAILADDRESS=\"$EMAILADDRESS\"" >> $SCRIPT/.backup
  414. SAVE="no"
  415. main_menu
  416. }
  417.  
  418. view_backup() {
  419. echo "Your configuration:" >$TEMP.summary
  420. echo "" >>$TEMP.summary
  421. echo "Main backup location: $BACKUPLOC" >>$TEMP.summary
  422. if [ ! "$MIRROR" = "" ]; then
  423. echo "Mirror location: $MIRROR" >>$TEMP.summary
  424. else
  425. echo "Mirror: disabled" >>$TEMP.summary
  426. fi
  427. echo "" >>$TEMP.summary
  428. if [ ! "$EXCLUDEDB" = "" ]; then
  429. echo "Excluded databases:" >>$TEMP.summary
  430. echo "$EXCLUDEDB" >>$TEMP.summary
  431. else
  432. echo "Exclude databases: disabled" >>$TEMP.summary
  433. fi
  434. DBNAMES="`$MYSQL --user=$USERNAME --password=$PASSWORD --host=localhost --batch --skip-column-names -e "show databases" | sed 's/ /%/g'`"
  435. for exclude in $EXCLUDEDB
  436. do
  437. DBNAMES=`echo $DBNAMES | sed "s/\b$exclude\b//g"`
  438. done
  439. echo "Databases included in the backup:" >>$TEMP.summary
  440. echo "$DBNAMES" >>$TEMP.summary
  441. echo "" >>$TEMP.summary
  442. if [ "$FTP" = "yes" ]; then
  443. echo "FTP Service: disabled during backup" >>$TEMP.summary
  444. else
  445. echo "FTP Service: enabled during backup" >>$TEMP.summary
  446. fi
  447. echo "" >>$TEMP.summary
  448. if [ ! "$EXCLUDEHTDOCS" = "" ]; then
  449. echo "Excluded directories:" >>$TEMP.summary
  450. echo "$EXCLUDEHTDOCS" >>$TEMP.summary
  451. else
  452. echo "Exclude directories: disabled" >>$TEMP.summary
  453. fi
  454. cd $HTFOLDER
  455. HTDOCSNAMES="`find -type d -maxdepth 1 | sed 's/\.//g;' | sed 's/\///g;' | sed -e '1,1d'`"
  456. for exclude in $EXCLUDEHTDOCS
  457. do
  458. HTDOCSNAMES=`echo $HTDOCSNAMES | sed "s/\b$exclude\b//g"`
  459. done
  460. echo "Directories included in the backup:" >>$TEMP.summary
  461. echo "$HTDOCSNAMES" >>$TEMP.summary
  462. echo "" >>$TEMP.summary
  463. if [ "$FTPDUMP" = "yes" ]; then
  464. echo "FTP dump: enabled" >>$TEMP.summary
  465. echo "FTP server IP: $FTPIP" >>$TEMP.summary
  466. echo "FTP directory: $FTPDIR" >>$TEMP.summary
  467. else
  468. echo "FTP dump: disabled" >>$TEMP.summary
  469. fi
  470. echo "" >>$TEMP.summary
  471. if [ "$LASTWEEK" = "yes" ]; then
  472. echo "Backup period: 14 days" >>$TEMP.summary
  473. else
  474. if [ "$ONEDAY" = "yes" ]; then
  475. echo "Backup period: 1 day" >>$TEMP.summary
  476. else
  477. echo "Backup period: 7 days" >>$TEMP.summary
  478. fi
  479. fi
  480. echo "" >>$TEMP.summary
  481. if [ "$EMAILADDRESS" = "" ]; then
  482. echo "Email confirmation: disabled" >>$TEMP.summary
  483. else
  484. echo "Email confirmation to: $EMAILADDRESS" >>$TEMP.summary
  485. fi
  486. echo "" >>$TEMP.summary
  487. dialog \
  488. --title "Configure Backup" \
  489. --textbox $TEMP.summary 20 60 2>/dev/null
  490. rm $TEMP.summary
  491. main_menu
  492. }
  493.  
  494. edit_backup() {
  495. dialog \
  496. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  497. --title "Configure Backup" \
  498. --menu "Select a function:" 0 0 0 \
  499. 1 "Enter main backup location" \
  500. 2 "Enter mirror location" \
  501. 3 "Database details" \
  502. 4 "Webserver details" \
  503. 5 "FTP dump" \
  504. 6 "Backup period" \
  505. 7 "Email confirmation" \
  506. 8 "Return to main menu" 2>$TEMP
  507.  
  508. if [ "$?" != "0" ] ; then main_menu ; fi
  509.  
  510. choice=`cat $TEMP`
  511. case $choice in
  512. 1) enter_mainbackup;;
  513. 2) enter_mirror;;
  514. 3) mysql_config;;
  515. 4) apache_config;;
  516. 5) ftp_config;;
  517. 6) backup_period;;
  518. 7) enter_email;;
  519. 8) main_menu;;
  520. esac
  521. }
  522.  
  523. backup_period() {
  524. dialog \
  525. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  526. --title "Configure Backup" \
  527. --radiolist "Select backup period\nUse SPACE to select" 0 0 0 \
  528. 1 "1 day" off \
  529. 2 "7 days" off \
  530. 3 "14 days" ON \
  531. 2>$TEMP
  532.  
  533. if [ "$?" != "0" ] ; then edit_network ; fi
  534.  
  535. choice=`cat $TEMP`
  536. case $choice in
  537. 1)
  538. ONEDAY="yes"
  539. LASTWEEK="no"
  540. ;;
  541. 2)
  542. ONEDAY="no"
  543. LASTWEEK="no"
  544. ;;
  545. 3)
  546. ONEDAY="no"
  547. LASTWEEK="yes"
  548. ;;
  549. esac
  550. save="yes"
  551. edit_backup
  552. }
  553.  
  554. enter_mainbackup() {
  555. dialog \
  556. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  557. --title "Configure Backup" \
  558. --inputbox "Please enter the main backup location:" 10 45 "$BACKUPLOC" 2>$TEMP
  559.  
  560. if [ "$?" != "0" ] ; then edit_backup ; fi
  561. BACKUPLOC=`cat $TEMP`
  562. SAVE="yes"
  563. enter_mirror
  564. }
  565.  
  566. enter_mirror() {
  567. dialog \
  568. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  569. --title "Configure Backup" \
  570. --inputbox "Please enter the mirror location:\nExample /mnt/hda2\n(leave empty to disable)" 10 45 "$MIRROR" 2>$TEMP
  571.  
  572. if [ "$?" != "0" ] ; then edit_backup ; fi
  573. MIRROR=`cat $TEMP`
  574. SAVE="yes"
  575. mysql_config
  576. }
  577.  
  578. mysql_config() {
  579. dialog \
  580. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  581. --title "Configure Backup" \
  582. --inputbox "Please enter your MySQL username" 10 45 "$USERNAME" 2>$TEMP
  583.  
  584. if [ "$?" != "0" ] ; then edit_backup ; fi
  585. USERNAME=`cat $TEMP`
  586.  
  587. dialog \
  588. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  589. --title "Configure Backup" \
  590. --insecure \
  591. --passwordbox "Please enter your MySQL password" 10 45 2>$TEMP
  592.  
  593. if [ "$?" != "0" ] ; then edit_backup ; fi
  594. PASSWORD=`cat $TEMP`
  595.  
  596. DBNAMES="`$MYSQL --user=$USERNAME --password=$PASSWORD --host=localhost --batch --skip-column-names -e "show databases" | sed 's/ /%/g'`"
  597.  
  598. if [ "$DBNAMES" = "" ]; then
  599. dialog \
  600. --sleep 2 \
  601. --infobox "Wrong username/password!" 3 30
  602. mysql_config
  603. fi
  604.  
  605. dialog \
  606. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  607. --title "Configure Backup" \
  608. --inputbox "Please enter databases (space separated) to EXCLUDE\nThe following databases are available:\n \n$DBNAMES" 15 60 "$EXCLUDEDB" 2>$TEMP
  609.  
  610. if [ "$?" != "0" ] ; then edit_backup ; fi
  611. EXCLUDEDB=`cat $TEMP`
  612.  
  613. dialog \
  614. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  615. --title "Configure Backup" \
  616. --yesno "Would you like to disable the FTP service during backup (to stop incoming data)?\nNote: backup might take a long time" 10 45
  617.  
  618. case $? in
  619. 0) FTP="yes";;
  620. 1) FTP="no";;
  621. 255) edit_backup;;
  622. esac
  623. SAVE="yes"
  624. apache_config
  625. }
  626.  
  627. apache_config() {
  628. cd $HTFOLDER
  629. HTDOCSNAMES="`find -type d -maxdepth 1 | sed 's/\.//g;' | sed 's/\///g;' | sed -e '1,1d'`"
  630. dialog \
  631. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  632. --title "Configure Backup" \
  633. --inputbox "Please enter directories (space separated) to EXCLUDE\nThe following directories are available:\n \n$HTDOCSNAMES" 15 60 "$EXCLUDEHTDOCS" 2>$TEMP
  634.  
  635. if [ "$?" != "0" ] ; then edit_backup ; fi
  636. EXCLUDEHTDOCS=`cat $TEMP`
  637. SAVE="yes"
  638. edit_backup
  639. }
  640.  
  641. ftp_config() {
  642. dialog \
  643. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  644. --title "Configure Backup" \
  645. --yesno "Would you like to enable the FTP dump?" 6 50
  646.  
  647. case $? in
  648. 0) FTPDUMP="yes";;
  649. 1) FTPDUMP="no";;
  650. 255) edit_backup;;
  651. esac
  652.  
  653. if [ "$FTPDUMP" = "yes" ]; then
  654. dialog \
  655. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  656. --title "Configure Backup" \
  657. --inputbox "Please enter your FTP username" 10 50 "$FTPUSERNAME" 2>$TEMP
  658.  
  659. if [ "$?" != "0" ] ; then edit_backup ; fi
  660. FTPUSERNAME=`cat $TEMP`
  661.  
  662. dialog \
  663. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  664. --title "Configure Backup" \
  665. --insecure \
  666. --passwordbox "Please enter your FTP password" 10 50 2>$TEMP
  667.  
  668. if [ "$?" != "0" ] ; then edit_backup ; fi
  669. FTPPASSWORD=`cat $TEMP`
  670.  
  671. dialog \
  672. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  673. --title "Configure Backup" \
  674. --inputbox "Please enter the FTP server IP address" 10 50 "$FTPIP" 2>$TEMP
  675.  
  676. if [ "$?" != "0" ] ; then edit_backup ; fi
  677. FTPIP=`cat $TEMP`
  678.  
  679. dialog \
  680. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  681. --title "Configure Backup" \
  682. --inputbox "Please enter the FTP server path" 10 45 "$FTPDIR" 2>$TEMP
  683.  
  684. if [ "$?" != "0" ] ; then edit_backup ; fi
  685. FTPDIR=`cat $TEMP`
  686. if [ "$FTPDIR" = "" ]; then
  687. FTPDIR="/"
  688. fi
  689. fi
  690. SAVE="yes"
  691. edit_backup
  692. }
  693.  
  694. enter_email() {
  695. dialog \
  696. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  697. --title "Configure Backup" \
  698. --yesno "Would you like to receive a daily email confirmation?" 8 45
  699.  
  700. case $? in
  701. 0) EMAIL="yes";;
  702. 1) EMAIL="no";;
  703. 255) edit_backup;;
  704. esac
  705.  
  706. if [ "$EMAIL" = "yes" ]; then
  707. dialog \
  708. --backtitle "by JF Nutbroek - www.mywebmymail.com" \
  709. --title "Configure Backup" \
  710. --inputbox "Please enter your email address:" 10 45 "$EMAILADDRESS" 2>$TEMP
  711.  
  712. if [ "$?" != "0" ] ; then edit_backup ; fi
  713. EMAILADDRESS=`cat $TEMP`
  714. else
  715. EMAILADDRESS=""
  716. fi
  717. SAVE="yes"
  718. edit_backup
  719. }
  720.  
  721. trap clean_up SIGHUP SIGINT SIGQUIT SIGKILL SIGTERM
  722.  
  723. case "$1" in
  724. 'start')
  725. start
  726. ;;
  727. 'config')
  728. setterm -background blue
  729. clear
  730. main_menu
  731. setterm -background black
  732. ;;
  733. 'disable')
  734. disable
  735. ;;
  736. 'enable')
  737. enable
  738. ;;
  739. 'restore')
  740. setterm -background blue
  741. clear
  742. restore
  743. setterm -background black
  744. ;;
  745. *)
  746. echo "Usage: backup_software config | start | disable | enable | restore"
  747. esac
  748.  
  749. exit 0
  750.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.