copy.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. echo "======================================="
  3. while read -p "Backup website: " back
  4. do if [[ -d $back ]]; then
  5. break
  6. else
  7. echo "$back not found, please try again"
  8. fi
  9. done
  10. #Variable
  11. bkdir=backup/
  12. web=$back/DocumentRoot
  13. #Check config
  14. if [ -f $web/wp-config.php ]; then
  15. config=$web/wp-config.php
  16. rm -f $back/wp-config.php
  17. elif [ -f $back/wp-config.php ]; then
  18. config=$back/wp-config.php
  19. else
  20. echo "Config website not found"
  21. exit
  22. fi
  23. #Variable
  24. user=$(grep DB_USER $config | awk -F\' '{print$4}')
  25. db=$(grep DB_NAME $config | awk -F\' '{print$4}')
  26. pass=$(grep DB_PASSWORD $config | awk -F\' '{print$4}')
  27. mkdir -p $bkdir
  28. #Backup database
  29. mysqldump --user $user --password=$pass $db > "$bkdir"backup.sql
  30. if [ $? -eq 0 ] ; then
  31. echo "Backup database successful"
  32. echo "======================================="
  33. else
  34. echo "Backup database fail"
  35. fi
  36. while read -p "Website restore: " restore
  37. do
  38. if [[ -d $restore ]]; then
  39. break
  40. else
  41. echo "$restore not found, please try again"
  42. fi
  43. done
  44. conf=$restore/wp-config.php
  45. u1=$(grep DB_USER $conf | awk -F\' '{print$4}')
  46. d1=$(grep DB_NAME $conf | awk -F\' '{print$4}')
  47. p1=$(grep DB_PASSWORD $conf | awk -F\' '{print$4}')
  48. rm -rf $restore/DocumentRoot
  49. mysql -u $u1 -p$p1 $d1 < "$bkdir"backup.sql
  50. if [ $? -eq 0 ] ; then
  51. echo "Restore database successful"
  52. else
  53. echo "Restore database fail"
  54. fi
  55. cp -r $web $ $restore > /dev/null 2>&1
  56. echo "Copy code website $domain successful"
  57. rm -rf $bkdir