Created
October 7, 2015 16:47
-
-
Save spicecadet/db6c1ce4f6ca7be923c3 to your computer and use it in GitHub Desktop.
This is a quick bash script I built to handle db export and docroot backup for my local vagrant box. Potentially useful if you are using a Vagrant box that does not backup files and db on Vagrant Destroy. Note that you'll need to add your password to run the copy command on line 31.
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 | |
# create variables for directories | |
main_backup_dir=$HOME/Development/backups | |
vagrant_dir=$HOME/Development/hgv/hgv_data | |
vagrant_root_dir=$HOME/Development/hgv | |
today="$(date +'%m-%d-%Y')"_daily_backup | |
daily_backup_dir=$HOME/Development/backup/$today | |
# print directories to screen for testing | |
echo ----------: Main backup dir: $main_backup_dir | |
echo ----------: Vagrant directory: $vagrant_dir | |
echo ----------: Daily backup directory: $daily_backup_dir | |
# mysql backup | |
cd ${vagrant_root_dir} | |
echo ----------: changed to vagrant directory | |
pwd | |
vagrant ssh --command "mysqldump -u root --all-databases > ${today}.sql" && | |
echo ----------: sql dump successful || echo ----------: sql dump failed | |
vagrant ssh --command "sudo mv ${today}.sql /hgv_data/sql-backup" && | |
echo ----------: sql dump moved to backup directory || echo ----------: sql dump failed to move into backup directory | |
# if backup directory does not exist create directory and copy files | |
if [ -d ${daily_backup_dir} ] | |
then | |
echo ----------: $daily_backup_dir exists | |
echo ----------: backup has alredy run today | |
echo "This is an automated status message" | mail -s "Local backup: alredy run today" [email protected] | |
else | |
mkdir ${daily_backup_dir} | |
echo your_password_here | sudo cp -r ${vagrant_dir} /$daily_backup_dir && | |
echo ----------: files copied && echo "This is an automated status message" | mail -s "Local backup: successful" [email protected] || | |
echo backup failed && echo "This is an automated status message" | mail -s "Local backup: failed" [email protected] | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment