Community Documentation

Bash scripts for backing up and copying a drupal site on linux

Last updated August 21, 2010. Created by kuschelhummer on August 18, 2010.
Log in to edit this page.

Bash scripts do an excellent job of making life easier in linux envrionments.

I use this one to make backups of my development site:

archive_instance

#!/bin/bash

#### Script for  putting drupal instance source and database content in one file
#### it follows the convention that direcotry name and database name match
#### eg. if you have drupal instance under sandbox the database name is sandbox, tooo


E_BADARGS=65
E_NOT_DIREXISTS=99
EXPECTED_ARGS=1


#### apply your settings here
BACKUPPATH=/var/archived_versions/
WWW_ROOT=/var/www/
MYSQLUSER=root
MYSQLPASSWORD=mypass


if [ $# -ne $EXPECTED_ARGS ]
then
  echo "This script will backup your site and database into one zip, stored in $BACCKUPPATH"
  echo "Usage: $0 sitedir "
  echo ":eg $0 sandbox for $WWW_ROOTsandbox and mysqldatabase sandbox"
  exit $E_BADARGS
fi

SOURCEDIR=$WWW_ROOT$1
echo $SOURCEDIR
# bash check if directory exists
if  [ ! -d $SOURCEDIR ]; then
echo "SOURCE Directory $SOURCEDIR does not exist, please check params"
exit $E_NOT_DIREXISTS

fi



OF=${BACKUPPATH}${1}archive_$(date +%Y_%m_%d_%T).zip
DUMP=${BACKUPPATH}dump_${1}_$(date +%Y%m%d).txt
echo $OF
zip -ru $OF $SOURCEDIR
mysqldump --user=$MYSQLUSER --password=$MYSQLPASSWORD $1 > $DUMP
zip -u $OF $DUMP
rm $DUMP

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Site administrators

Installation Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.