Skip to content

Commit

Permalink
Merge pull request #5 from russellmacshane/dev
Browse files Browse the repository at this point in the history
Dev into Master
  • Loading branch information
russellmacshane authored Oct 26, 2019
2 parents c0bde72 + c642938 commit c8de747
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vagrant
*.log
backup
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ The goal of this project is to create a quick virtual machine setup with a WordP
5. WordPress files are located in `/var/www/html` and you can run WPCli commands from there
6. This repo is mirrored from your local machine over to `/quick-wordpress` on your vm

## Backup and Restores
1. In order to do backup and restores login to your virtual machine - `$ vagrant ssh`
2. `$ cd /quick-wordpress`
3. `$ ./backup.sh` and follow the on screen instructions
4. Backups are saved in the `/quick-wordpress/backups` directory
5. If you'd like to restore from a previous backup - `$ ./restore.sh` and follow the on screen instructions

## Cleanup
1. If you are ready to delete your WordPress VM from you local machine - `$ vagrant destroy -f`

## Project Roadmap
* ~~LAMP Stack installed on Virtual Machine with WordPress using Vagrant~~
* Plugin installations on initial WordPress install
* Site Backups
* Site Restores
* ~~Plugin installations on initial WordPress install~~
* ~~Site Backups~~
* ~~Site Restores~~
* Web Application instead of bash scripts for WordPress install, backup, and restore
* Modifications to WP details in order to give a working WordPress backup to a host
39 changes: 39 additions & 0 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

source /quick-wordpress/config

echo "***************************** WordPress Backup **************************"
run=true
while $run
do
read -r -p "Would you like to name your backup? [Y/n] " input

case $input in
[yY][eE][sS]|[yY])
read -p "Enter the filename of your backup: " file
backup_file=$file.tar.bz2
echo "Will name backup $backup_file"
run=false
;;

[nN][oO]|[nN])
backup_file=$(date '+%F_%s').tar.bz2
echo "Will name backup $backup_file"
run=false
;;

*)
echo "Invalid input..."
;;
esac
done

echo "***************************** Backup Database ****************************"
sudo mysqldump $wp_db > datadump.sql

echo "***************************** Backups Files ******************************"
mkdir -p /quick-wordpress/backup
tar -cjvf /quick-wordpress/backup/$backup_file /var/www/html datadump.sql

echo "***************************** Cleanup ************************************"
rm datadump.sql
29 changes: 29 additions & 0 deletions restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

source /quick-wordpress/config

echo "***************************** WordPress Restore **************************"
read -p "Enter the filename of the backup you would like to restore: " file

backup_file=/quick-wordpress/backup/$file

if [ ! -f $backup_file ]; then
echo "$backup_file not found!" 1>&2
exit 1
fi

echo "***************************** Unpack Backup ******************************"
mkdir -p /tmp/wp-bkup
tar -xjvf $backup_file -C /tmp/wp-bkup

echo "***************************** Nuke WP Installation ***********************"
sudo rm -rf /var/www/html/*

echo "***************************** Restore Files ******************************"
sudo mv /tmp/wp-bkup/var/www/html/* /var/www/html/

echo "***************************** Restore Database ***************************"
sudo mysql $wp_db < /tmp/wp-bkup/datadump.sql

echo "***************************** Cleanup ************************************"
rm -rf /tmp/wp-bkup

0 comments on commit c8de747

Please sign in to comment.