# 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).
On Mon, Aug 17, 2009 at 7:51 PM, Chris Miller <[email protected]>wrote: > This is a rather fun problem. I just want someone to help check my work, > mostly. Here goes. > > I'm switching web hosts because my current VPS provider is worse than > another one I found. I keep my domain registered with a third party so I > can switch around as much as I want. So I'm writing a shell script I can > run on my machine to back up relevant files and to then save them to my OS X > laptop. I will use these files when populating the new VPS image. I have > set up RSA key authentication so that SSH won't prompt for my password > approximately a billion times. > > As I am a rather BSD-ish kind of fellow, feel absolutely free to take this > script and modify and use it to your heart's delight. If you know of any > better commands/methods to do this, also do tell! > > Here's my script. If you see any problems, syntax errors, etc. please let > me know! It's not something I feel safe about just running as it could > leave annoying files all over my webserver - which wouldn't be too much fun. > > #!/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 > scp -r [email protected]:/home ${BACKUPDIR}/home > > # /var > mkdir ${BACKUPDIR}/var > > # /var/svn > mkdir ${BACKUPDIR}/var/svn > scp -r [email protected]:/var/svn ${BACKUPDIR}/var/svn > > # /var/git > mkdir ${BACKUPDIR}/var/git > scp -r [email protected]:/var/git ${BACKUPDIR}/var/git > > # /opt > mkdir ${BACKUPDIR}/opt > > # /opt/redmine > mkdir ${BACKUPDIR}/opt/redmine > scp -r [email protected]:/opt/redmine ${BACKUPDIR}/opt/redmine > > # /root > mkdir ${BACKUPDIR}/root > scp -r [email protected]:/root ${BACKUPDIR}/root > > # /etc > mkdir ${BACKUPDIR}/etc > > # /etc/apache2 > mkdir ${BACKUPDIR}/etc/apache2 > > # /etc/apache2/sites-available > mkdir ${BACKUPDIR}/etc/apache2/sites-available > scp -r [email protected]:/etc/apache2/sites-available > ${BACKUPDIR}/etc/apache2/sites-available > > # /etc/cron.d > mkdir ${BACKUPDIR}/etc/cron.d > scp -r [email protected]:/etc/cron.d ${BACKUPDIR}/etc/cron.d > > # /etc/cron.hourly > mkdir ${BACKUPDIR}/etc/cron.hourly > scp -r [email protected]:/etc/cron.hourly ${BACKUPDIR}/etc/cron.hourly > > # /etc/cron.daily > mkdir ${BACKUPDIR}/etc/cron.daily > scp -r [email protected]:/etc/cron.daily ${BACKUPDIR}/etc/cron.daily > > # /etc/cron.weekly > mkdir ${BACKUPDIR}/etc/cron.weekly > scp -r [email protected]:/etc/cron.weekly ${BACKUPDIR}/etc/cron.weekly > > # /etc/cron.monthly > mkdir ${BACKUPDIR}/etc/cron.monthly > scp -r [email protected]:/etc/cron.monthly ${BACKUPDIR}/etc/cron.monthly > > # backup mysql > DBS=ssh [email protected] "mysql -u $MUSER -h $MHOST -p$MPASS -Bse 'show > databases'" > for db in $DBS do > REMOTEFILE=/root/mysql-$db.$NOW-$(date +"%T").gz > FILE=$BACKUPDIR/mysql-$db.$NOW-$(date +"%T").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/ > > > > > -- Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
