Advertisement
Guest User

Untitled

a guest
Aug 11th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/bin/env bash
  2. #
  3. # Author: Amado Martinez - AmadoMartinez.mx
  4. # License: MIT License
  5. # Date: 2016-08-11
  6. #
  7. # Backup a complete wordpress installation
  8. #
  9.  
  10. if [ $# -lt 2 ] ; then
  11. head -n 10 "$0" | grep "^#" | tail -n +2
  12.  
  13. echo -e "\nUsage:\n\t$0 wordpress-directory backup-storage-directory"
  14. echo
  15. exit
  16. fi
  17.  
  18. # todo add support for PORT config
  19. readconf (){
  20. # $1 can be: NAME, USER, PASSWORD, HOST, CHARSET, COLLATE
  21. valstr=$(grep "DB_$1" "$2/wp-config.php" | cut -d"'" -f4)
  22.  
  23. if [ "$1" == "HOST" ] ; then
  24. echo "$valstr" | cut -d: -f1
  25. else
  26. echo "$valstr"
  27. fi
  28. }
  29.  
  30.  
  31. datestr=$(date +%Y%m%d)
  32. destinationdir="$2/$datestr/"
  33. wpdir="$1"
  34.  
  35. db_name=$(readconf NAME "$wpdir")
  36. db_user=$(readconf USER "$wpdir")
  37. db_pass=$(readconf PASSWORD "$wpdir")
  38. db_host=$(readconf HOST "$wpdir")
  39.  
  40. echo "Creating $destinationdir .."
  41. mkdir -p "$destinationdir"
  42.  
  43. echo "Backing up database.."
  44. mysqldump -u "$db_user" "-p$db_pass" -h "$db_host" "$db_name" > "$destinationdir/$db_name.sql"
  45.  
  46. echo "Creating Tar File"
  47. tar -czf "$destinationdir/wordpress-site.tar.gz" "$wpdir"
  48.  
  49. echo "Finished backup to $destinationdir"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement