Last active
August 29, 2015 14:01
-
-
Save trepmal/555116701668fd52198b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo '==Archiving==' | |
echo 'Which site (slug as used in nginx conf)?' | |
read site | |
if [[ -z "$site" ]]; then | |
exit; | |
fi | |
nginxconf="/etc/nginx/conf.d/${site}.conf" | |
if [ ! -f $nginxconf ]; then | |
echo 'Nginx site conf not found. Exiting.' | |
exit; | |
fi | |
echo $nginxconf | |
pattern='root\s*([^;]*?);' | |
if [[ `cat $nginxconf` =~ $pattern ]]; then | |
path=${BASH_REMATCH[1]} | |
else | |
echo 'Could not determine web root.' | |
echo 'Manually enter?' | |
read path | |
fi | |
if [ ! -d $path ]; then | |
echo 'Could not find web root. Exiting.' | |
exit; | |
fi | |
echo "Moving into web root: $path" | |
cd $path | |
cp $nginxconf . | |
echo 'Exporting db...' | |
/usr/bin/wp db export --allow-root | |
echo 'Done' | |
echo 'Archiving webroot...' | |
archive="${site}.tar.gz" | |
tar -czf $archive ./ --exclude=$archive | |
echo 'Done' | |
archivefp=`readlink -e $archive` | |
echo 'Would you like to clean up the original files?' | |
echo "Delete $nginxconf" | |
echo "Delete $path" | |
dbname=`/usr/bin/wp eval "echo DB_NAME;" --allow-root` | |
echo "Drop database: $dbname" | |
echo 'Enter "yes" to proceed' | |
read cleanup | |
if [[ "$cleanup" == "yes" ]]; then | |
echo "Cleaning up..." | |
mv $archive ../ | |
archivefp=`readlink -e ../$archive` | |
dbuser=`/usr/bin/wp eval "echo DB_USER;" --allow-root` | |
# dbpass=`/usr/bin/wp eval "echo DB_PASSWORD;" --allow-root` | |
# dbhost=`/usr/bin/wp eval "echo DB_HOST;" --allow-root` | |
dbadmin='' | |
dbpass='' | |
dbhost='' | |
dbip='' | |
#echo "rm $nginxconf" | |
rm $nginxconf | |
# echo "rm -rf $path/" | |
rm -rf $path/ | |
if [[ "$dbadmin" != "" ]]; then | |
# echo "mysqladmin -u $dbadmin -h $dbhost -p$dbpass drop $dbname" | |
mysqladmin -u $dbadmin -h $dbhost -p$dbpass drop $dbname | |
# echo "mysql -u $dbadmin -h $dbhost -p$dbpass -e \"DROP USER '$dbuser'@'$dbip';\"" | |
mysql -u $dbadmin -h $dbhost -p$dbpass -e "DROP USER '$dbuser'@'$dbip';" | |
fi | |
service nginx reload | |
echo 'Done.' | |
fi | |
echo "Here's your archive which contains: | |
- nginx site conf | |
- db export | |
- webroot" | |
ls -al $archivefp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment