I’ve written the following Bash script used to duplicate a webapp/website you have (say, a WordPress website) locally on your server environment, for testing purposes, indicating after 2 days if you have yet to delete it after you’ve finished your testing.
Here’s the code:
cat <<-'DWA' > /opt/dwa.sh #!/bin/bash DWA() { tiesto='tiesto' read domain find /var/www/html $ {domain} -exec cp $ {domain} $ {tiesto} {} \; sed -i 's/$ {domain}/$ {tiesto}'/g /var/www/html/tiesto/wp-config sed -i 's/$ {domain}/$ {tiesto}'/g /var/www/html/tiesto/wp-config mysql -u root -p << MYSQL create user '$ {tiesto}'@'localhost' identified by '$ {psw}'; create database $ {tiesto}; GRANT ALL PRIVILEGES ON $ {tiesto}.* TO $ {tiesto}@localhost; MYSQL sleep 2d echo "If you haven't already, eliminate tiesto (dir & db)." tmux kill-session } DWA DWA chmod +x /opt/dwa.sh && cat >> /etc/bash.bashrc <<< "alias dwa='tmux new-session -d bash /opt/dwa.sh'"
After a reboot
(due to the added alias), run it by the alias + an argument to indicate the app you’re working on.
For example, if you named the app/site as example.com (I assume you named the site’s dir, the DB user, and the DB instance the same), execute this in Bash:
dwa example.com
The webapp/site should be duplicated.
I would appreciate your review.