Developing and testing against live
I usually develop locally on a VM. I generally have more confidence if I'm developing on a platform which is as much like live as possible - and this usually means copying the live database to my local dev environment.
Here's a script I use to help develop this blog:#!/bin/bash
# location of the remote file
origin="deglos.com:/backups/current.sql.gz"
# Local path to store the db backup
path=/var/www/vhosts/blog.deglos.com/database/
file=current.sql.gz
# Local database name
db=deglos_blog
##################################################
# Unix timestamps...
# Modified-time of the file: stat -c %Y
# Current time: date +%s
# 1 day (in seconds): 86400
if [ -e $file ]; then
age=$[`date +%s` - `stat -c %Y $path$file`]
fi
if [ ! $age ] || [ $age -gt 86400 ]; then
echo "Fetching remote file"
scp $origin $file
fi
echo "Extracting the database backup from the gzip archive"
# Copy to /tmp
cp -f $path$file /tmp
# gunzip the file
gunzip -f /tmp/$file
# remove the .gz from the file variable
file=${file:0:${#file}-3}
# reset the DB
echo "Removing the old database"
mysql -e "DROP DATABASE $db; CREATE DATABASE $db;"
# Import the DB
echo "Importing from the database backup"
mysql $db < /tmp/$file
echo "Done"#!/bin/bash # Store backup in this directory: dir="/backups" # Backups will be stored in the pattern $filename-date-time.sql.gz filename="blog.deglos.com" # Database to backup db=blog ################################# # Bash script to dump the blog database, zip it, and move it to $dir. date=`date +%Y%m%d` time=`date +%H%M%S` filename=$filename-$date-$time.sql mysqldump -C $db > /tmp/$filename gzip /tmp/$filename mv /tmp/$filename.gz $dir # symlink current.sql.gz rm -f $dir/current.sql.gz ln -s $dir/$filename.gz $dir/current.sql.gz


Add new comment