Skip to content

Instantly share code, notes, and snippets.

@spyesx
Last active June 11, 2018 12:13
Show Gist options
  • Save spyesx/d2bc8c45c6391869f0ce68f42c92e6ce to your computer and use it in GitHub Desktop.
Save spyesx/d2bc8c45c6391869f0ce68f42c92e6ce to your computer and use it in GitHub Desktop.
Very quick and VERY dirty WordPress backup and reset
#!/bin/bash
# Reset a wordpress
# sudo sh reset_wordpress.sh website_name database_name /path/to/document/root/
# TODO
# - Add some user input tests
# - Add some FS tests
NAME=$1
DBNAME=$2
CUSTOMPATH=$3
printf "$(tput setaf 4)Create directory:$(tput sgr 0) $NAME \n "
mkdir $NAME
cd $NAME
printf "$(tput setaf 4)Create a ZIP archive of$(tput sgr 0) $CUSTOMPATH $(tput setaf 4)into$(tput sgr 0) $NAME \n "
zip -r "$NAME.zip" $CUSTOMPATH
mkdir database
cd database
sh wipe_db.sh $DBNAME
cd $CUSTOMPATH
printf "$(tput setaf 4)Processing: Remove all files into$(tput sgr 0) $CUSTOMPATH \n\n"
rm -R ./*
printf "$(tput setaf 4)Processing: Download WordPress$(tput sgr 0) \n\n"
wget https://wordpress.org/latest.zip
printf "$(tput setaf 4)Processing: Unzip$(tput sgr 0) lastest.zip \n\n"
unzip -j latest.zip
printf "$(tput setaf 4)Processing: Clean up"
rm latest.zip
printf "$(tput setaf 4)Processing: Update user and group access$(tput sgr 0) \n\n"
chown -R www-data:www-data .
printf "$(tput setaf 2)Reset done$(tput sgr 0) \n\n"
#!/bin/bash
# Backup & Wipe a database
# sudo sh wipe_db.sh dbname
DBUSER="xxxxxxxxxxxx"
DBPASS="yyyyyyyyyyyyyy"
DBNAME="$1"
# Require the database argument.
[ $# -eq 0 ] && {
echo "Please specify a valid MySQL database: $0 [database_goes_here]" ;
exit 1;
}
printf "Create a backup of $DBNAME"
mysqldump -u$DBUSER -p$DBPASS $DBNAME > "$DBNAME.sql"
printf "Drop $DBNAME"
mysql -u$DBUSER -p$DBPASS -Nse 'show tables' $DBNAME | while read table; do mysql -u$DBUSER -p$DBPASS -e "drop table $table" $DBNAME; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment