FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Home » Shell Scripting » Shell Scripts for Dreamhost

Shell Scripts for Dreamhost

Shell Scripts for Dreamhost Example shell scripts (bash or sh) that automate and easyate tasks from within the dreamhost ssh env

Shell Scripts for Dreamhost

January 16th, 2007

Example shell scripts (bash or sh) that automate and easyate tasks from within the dreamhost ssh env


Backup Site Directory

Place this script backup.sh in your DOCROOT for each of your sites.

MYSITES :    /home/username/sites/askapache.com
MYSITE  :    askapache.com
MYSITEBK:    askapachecom
MYUSER  :    username
MYGROUP :   groupname
MYGROUPS:
MYFNAME :    askapachecom-01x16x07.tgz
MYFNAMEX:    askapachecom-01x16x07-08x43.tgz
MYBNAME :    /home/username/backups/SITES/askapache.com/askapachecom-01x16x07.tgz
MYBNAMEX:    /home/username/backups/SITES/askapache.com/askapachecom-01x16x07-08x43.tgz
MYBDIR  :    sites/askapache.com/

The Script

#!/bin/sh
 
# SETTINGS
export MYSITES=`pwd -L`
export MYSITE=`basename ${MYSITES}`
export MYSITEBK=${MYSITE%%.*}${MYSITE#*.}
export MYUSER=`whoami`
export MYGROUP=`groups`
 
#======================  GLOBAL VARIABLES  =================================
# FILES #
export MYFNAME=${MYSITEBK}-`date +%mx%dx%y.tgz`
export MYFNAMEX=${MYSITEBK}-`date +%mx%dx%y-%Hx%M.tgz`
export MYBNAME=${HOME}/backups/SITES/${MYSITE}/${MYFNAME};
export MYBNAMEX=${HOME}/backups/SITES/${MYSITE}/${MYFNAMEX};
export MYBDIR=sites/${MYSITE}/
 
# COLORS #
cR='\E[31;1m'
cG='\E[32;1m'
cY='\E[33;1m'
 
#======================  GLOBAL FUNCTIONS  =================================
# pheader #
function pheader {
cd ${HOME}
clear
tput sgr0
echo -e "$cG\n\n"
echo '  _____________________________________________________________________ '
echo ' |                                                                     |'
echo ' |                                                                     |'
echo ' |                                                                     |'
echo " |                       SiteBack v.1.1 ${MYSITE}"
echo ' |                                                                     |'
echo ' |                                                                     |'
echo ' |                                                                     |'
echo '  _____________________________________________________________________ '
echo -e "$cG\n\n"
tput sgr0
sleep 3
}
 
# pfooter #
function pfooter {
tput sgr0
echo -e "$cG"
echo '  _____________________________________________________________________ '
echo ' |                                                                     |'
echo ' |                    SiteBack COMPLETED SUCCESSFULLY                  |'
echo '  _____________________________________________________________________ '
echo -e "\n\n\n"
tput sgr0
cd ${OLDPWD}
}
 
#======================  MAIN  =================================
 
pheader
 
echo -e "$cY\n   @@@ CHECK FOR PRESENCE OF BACKUP FILE"
if [ -e $MYBNAME ] ; then
        echo -e "$cR      !!! FILE FOUND.. CHANGING DESTINATION"
                MYBNAME=${MYBNAMEX}
else
        tput sgr0
fi
echo -e "$cG\n   [ DONE ]\n\n"
 
echo -e "$cY\n   @@@ CHANGING FILES TO CORRECT GROUP AND USER PERMISSIONS... "
echo -e "$cG\n   [ DONE ]\n\n"
sleep 2
 
echo -e "$cY\n   @@@ BACKUP IN PROGRESS... "
sleep 5
 
tput sgr0
tar -czf ${MYBNAME} ${MYBDIR}
echo -e "$cG\n   [ DONE ]\n\n"
 
pfooter
 
exit 0;

Add Comment!

Leave a Reply

Your email address will not be published.


Google +

It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

Site Map | Contact Webmaster | Glossary | License and Disclaimer | Terms of Service |

↑ TOPMain