On Aug 17, 2009, at 6:37 PM, Daniel Eggleston wrote:

> # backup mysql
> DBS=ssh [email protected] "mysql -u $MUSER -h $MHOST -p$MPASS -Bse  
> 'show databases'"
>  should be (note backticks):
> # backup mysql
> DBS=`ssh [email protected] "mysql -u $MUSER -h $MHOST -p$MPASS -Bse  
> 'show databases'"`
> Also, you can use the "mkdir -p" command to make a directory &  
> subdirectories in one swoop
> i.e. instead of
> mkdir /var
> mkdir /var/svn
> you can run:
> mkdir -p /var/svn
> Lastly, you might try rsync.  scp is great for a one shot thing, but  
> if you're planning on making this a regular backup script, you  
> should use rsync (it will only copy updated files).


Ah, yes, Rsync... I'd completely forgotten about that little wonder!   
It works so much better now!  I did know about mkdir -p, however I was  
sticking with the longer format for typography reasons trying to show  
the tree of files I was specifically cherry-picking out of the  
filesystem.

This is the final version of the script I got to work:

#!/bin/sh
# backup script for the whole FSDEV system

BACKUPDIR=/Users/cmiller/fsdev_backup
MHOST=localhost
MUSER=**********
MPASS=**********
NOW=`date +"%s"`

#mkdir ${BACKUPDIR}

# home directories
mkdir ${BACKUPDIR}/home
rsync -rv  [email protected]:/home ${BACKUPDIR}/

# /var
mkdir ${BACKUPDIR}/var

# /var/svn
mkdir ${BACKUPDIR}/var/svn
rsync -rv [email protected]:/var/svn ${BACKUPDIR}/var

# /var/git
mkdir ${BACKUPDIR}/var/git
rsync -rv [email protected]:/var/git ${BACKUPDIR}/var

# /opt
mkdir ${BACKUPDIR}/opt

# /opt/redmine
mkdir ${BACKUPDIR}/opt/redmine
rsync -rv [email protected]:/opt/redmine ${BACKUPDIR}/opt/

# /root
mkdir ${BACKUPDIR}/root
rsync -rv [email protected]:/root ${BACKUPDIR}/

# /etc
mkdir ${BACKUPDIR}/etc

# /etc/apache2
mkdir ${BACKUPDIR}/etc/apache2

# /etc/apache2/sites-available
mkdir ${BACKUPDIR}/etc/apache2/sites-available
rsync -rv [email protected]:/etc/apache2/sites-available ${BACKUPDIR}/etc/ 
apache2

# /etc/cron.d
mkdir ${BACKUPDIR}/etc/cron.d
rsync -rv [email protected]:/etc/cron.d ${BACKUPDIR}/etc

# /etc/cron.hourly
mkdir ${BACKUPDIR}/etc/cron.hourly
rsync -rv [email protected]:/etc/cron.hourly ${BACKUPDIR}/etc

# /etc/cron.daily
mkdir ${BACKUPDIR}/etc/cron.daily
rsync -rv [email protected]:/etc/cron.daily ${BACKUPDIR}/etc

# /etc/cron.weekly
mkdir ${BACKUPDIR}/etc/cron.weekly
rsync -rv [email protected]:/etc/cron.weekly ${BACKUPDIR}/etc

# /etc/cron.monthly
mkdir ${BACKUPDIR}/etc/cron.monthly
rsync -rv [email protected]:/etc/cron.monthly ${BACKUPDIR}/etc

# backup mysql
DBS=`ssh [email protected] "mysql -u $MUSER -h $MHOST -p$MPASS -Bse 'show  
databases'"`
echo $DBS
for DB in $DBS; do
        REMOTEFILE=/root/mysql-$DB-$NOW.gz
        FILE=${BACKUPDIR}/mysql-${DB}-${NOW}.gz
        ssh [email protected] "mysqldump -u $MUSER -h $MHOST -p$MPASS $DB | gzip  
-9 > $REMOTEFILE"
        scp [email protected]:$REMOTEFILE $FILE
        ssh [email protected] "rm -f $REMOTEFILE"
done

Registered Linux Addict #431495
For Faith and Family! | John 3:16!
http://www.fsdev.net/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Linux Users Group.
To post a message, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit our group at 
http://groups.google.com/group/linuxusersgroup
-~----------~----~----~----~------~----~------~--~---

Reply via email to