#!/bin/bash
#
# Bjorn's multisite backup V1.0
#
# Full backup of website of a drupal multisite install.
#
# Most multisite drupal installs have one directory tree and multiple
# sql databases. Using this script, you can back them all up.
# This is useful for a handful of site. If you have hundreds of sites
# or something crazy like that, you will need another solution.
#
# This script is loosly based on the fullsite backup script
# drom drupal.org, and suffers from some of the same disadvantages,
# such as no database/site locking, but it basically works.
#
# To use, modify the variables as required in the configuration section
# and stick this in a cron job. run it in the directory where you want
# your backups created. Please note if this file has been modified from
# the original.
# by Bjorn Roche
# copyright:
# There was no copyright notice on the original fullsite backup script,
# so I don't know what to say about this. However, I make no claims to
# this version.
# However, I do appreciate if you could leave my name on it, so that
# people know where to send corrections and enhancements to.
# Warranty:
# This script comes with absolutely no warranty, express or implied,
# including fitness for any purpose.
# It is solely your responsibility to read the code, understand it,
# and make sure the executable portion is correct and applicable to
# your application. It is provided as is, and could not and would
# not be provided at all with a waranty of any kind.
# Use it at your own risk.
# ------ start of configuration ---- #
# backup prefix
prefix=multisite-backup
# Website Files
webrootdir=/home/xodrupal/drupal-sites # (e.g.: webrootdir=/home/user/public_html)
# site list
# List each site you want to backup in parentheses.
sites=(site1.com site2.com site3.org)
# database info lists
# for each item, specify the required info in a list.
# the list items must be in the same order as the list of sites
# so that everything corresponds.
dbname=(db1 db2 db3)
dbhost=(db.site1.com db.site2.com db.site3.org)
dbuser=(user1 user2 user3)
dbpass=(pass1 pass2 pass3)
# ------ end of configuration ------ #
# setup some constants:
datestamp=`date +'%Y-%m-%d'`
numsites=${#sites[*]}
startdir=`pwd`
tempdir=tmpbckdir-$datestamp
tarname=$prefix-$datestamp.tgz
#
# Banner
#
echo ""
echo "bjorn's multisite backup V1.0"
#
# Create temporary working directory
#
echo " .. Setting up temporary working dir"
mkdir $tempdir
mkdir $tempdir/$prefix-$datestamp
echo " done"
#
# TAR website files
#
echo " .. TARing website files in $webrootdir"
cd $webrootdir
tar cf $startdir/$tempdir/$prefix-$datestamp/filecontent.tar .
echo " done"
#
# dump each database
#
i=0
echo " .. sqldump'ing $numsites databases:"
while [ $i -lt $numsites ]; do
echo "dumping user: ${dbuser[$i]}; database: ${dbname[$i]}; host: ${dbhost[$i]}..."
cd $startdir/$tempdir/$prefix-$datestamp
mysqldump -p${dbpass[$i]} --user=${dbuser[$i]} --host=${dbhost[$i]} --add-drop-table ${dbname[$i]} > ${sites[$i]}-dbcontent.sql
echo " done"
let i++
done
#
# Create final backup file
#
echo " .. Creating final compressed (tgz) TAR file: $tarname"
cd $startdir/$tempdir
tar czf $tarname $prefix-$datestamp
mv $tarname $startdir
echo " done"
#
# Cleanup
#
echo " .. Clean-up"
cd $startdir
rm -r $tempdir
echo " done"
#
# Exit banner
#
echo " .. multi-site backup complete"
echo ""
Wednesday, July 14, 2010
Drupal multisite backups
I run a few sites from a single drupal install. The drupal website has a nice bash script for backing up a single site, and a multisite backup script written in perl. Instead of using the perl script, I decided to modify the single-site backup script. Their perl script looks like it's a bit more flexible, but this more than does the job for most setups. Maybe others will find this useful. I just wrote it and did some cursory testing, but it seems like it checks out, and it's pretty simple:
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment