Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!

wordpress backup script

By: chrismccoy on Nov 21st, 2011  |  syntax: Bash  |  size: 0.81 KB  |  hits: 365  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. # usage: ./wpbackup.sh domain.com
  4.  
  5. DOMAIN="$1"; # domain name to backup
  6. BACKUP="$HOME/backups"; # store backups here
  7. HOSTPATH="$HOME/domains"; # path where hosted domains are
  8.  
  9. backmeup () {
  10.     local _N _U _P _H FS FT TD WP;
  11.     FT=`date +$BACKUP/$DOMAIN-%m-%d-%g-%H%M.tar.gz`;
  12.     FS=`date +$BACKUP/$DOMAIN-%m-%d-%g-%H%M.sql`;
  13.     TD=$HOSTPATH/$DOMAIN;
  14.     WP=$TD/wp-config.php;
  15.     ( cd $TD || {
  16.         echo "bad $TD" && return 2
  17.     };
  18.     eval $(sed -n "s/^d[^D]*DB_\([NUPH]\)[ASO].*',[^']*'\([^']*\)'.*/_\1='\2'/p" $WP);
  19.     mysqldump -u$_U -p$_P -h$_H $_N > $FS;
  20.     tar -czPf $FT $TD )
  21. }
  22.  
  23. if [ "$#" -ne 1 ]; then
  24.     echo "usage: $0 domain.com"
  25.     exit 0
  26. fi
  27.  
  28. if [ -d "$HOSTPATH/$DOMAIN/" ]; then
  29.     backmeup
  30.     exit 0
  31. else
  32.     echo "directory not found"
  33.     exit 0
  34. fi
  35.