Created
June 1, 2018 10:21
-
-
Save StuMason/16b027fb8bcef0c557e45d1c97ce8c91 to your computer and use it in GitHub Desktop.
remove.sh
This file contains hidden or 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 | |
# tars then deletes the NGINX file, /var/www/directory and mysql DB for $DOMAIN passed in first argument e.g | |
# sudo bash remove.sh domain.co.uk | |
# needs /root/.my.conf set up with [client] root user and password to create DB | |
# MAKESURE /root/backup/ exists before running this, haha. | |
DOMAIN=$1 | |
mysqldump ${DOMAIN//[^a-zA-Z_-]/_} > /root/backup/${DOMAIN}/db/${DOMAIN//[^a-zA-Z_-]/_} | |
mkdir -p /root/backup/${DOMAIN}/nginx | |
mkdir -p /root/backup/${DOMAIN}/www | |
mkdir -p /root/backup/${DOMAIN}/db | |
cp /etc/nginx/sites-available/${DOMAIN} /root/backup/${DOMAIN}/nginx/${DOMAIN} | |
cp -r /var/www/${DOMAIN} /root/backup/${DOMAIN}/www/${DOMAIN} | |
tar -czvf /root/backup/${DOMAIN}.tar.gz /root/backup/${DOMAIN} | |
#Let's hope all that succeeded... | |
rm -rf /etc/nginx/sites-available/${DOMAIN} | |
rm -rf /etc/nginx/sites-enabled/${DOMAIN} | |
rm -rf /var/www/${DOMAIN} | |
mysql --defaults-extra-file=/root/.my.conf -e "DROP DATABASE IF EXISTS ${DOMAIN//[^a-zA-Z_-]/_};" | |
rm -rf /root/backup/${DOMAIN} | |
printf "/root/backup/${DOMAIN}.tar.gz created." | |
sudo systemctl reload nginx | |
sudo systemctl restart nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment