[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cobalt-users] raqbackup.sh version 2.0



Hi list!

Last week I posted a shell-script to backup Cobalt RaQs to another
server using the Cobalt Migration Utility and FTP. Jeff Bilicki
released a new version of his CMU and the posted shell-script IS NOT
compatible with this new version. So here is a new version of the
shell-script which should work both with CMU 1.x and CMU 2.x on any
Cobalt RaQ.

I recommend to upgrade to CMU 2.x. You can download CMU 2.x from
ftp://ftp.cobaltnet.com/pub/users/jeffb/cmu/ and install it via your
webinterface.

For MySQL-users I added the possibility to backup all databases using
mysqldump.

Installation/Configuration:

1. Edit the configuration-section of the script

SOURCE
   hostname (FQDN) of the Source-RaQ. Please use the hostname of your
   home site.

CMUEXPORT
   location of cmuExport (there should be no need to change)

MYSQLDUMP
   location of mysqldump. If you use mysql telnet/ssh to your machine
   and do a "locate mysqldump" to find the path to mysqldump on your
   machine. If you don't have mysql or don't want to backup your
   databases empty this line.

MYSQLPASS - password for the mysql-root-account

TARGET
   hostname (FQDN) of the target machine on which you'll transfer the
   backup-files. The target machine should be in the LAN of the source
   machine because there are several huge files to transfer :-)

TARGETUSER
   Username on the target machine. It's recommended not to use the
   admin-user. So add a new user (e.g. username backup) on the target
   machine and give him a lot of quota.

TARGETPASS
   Password of TARGETUSER

2. Telnet/SSH to your source machine. su to root. I recommend to start
raqbackup.sh everyday, so

  cd /etc/cron.daily
  pico -w raqbackup.sh

(Copy the configured script to your clipboard and paste it into pico.
[CTRL]+[x] to exit pico. Save the file [y])

  chown 700 raqbackup.sh

3. Be sure you installed CMU on the Source-RaQ and you added the user
backup to the Target-Machine.

4. You'll get a mail with the cmuExport-output and possible ftp-errors
(it's normal that you get an entry about a not found mysqldump-file
if you don't use the mysql-backup and that you get an entry about a
not found backup.md5lst if you use CMU 2.x instead of 1.x.

5. On my machines (RaQ3/RaQ4) raqbackup.sh needs 20-50 minutes to
cmuExport all sites and ftp them to the backup-machine. I have arround
150 sites with 1.5 GB data per raq.

5. After two days you'll have two backup-versions (the cmuExport from
today and yesterday) per source raq on your target raq:

/home/sites/users/backup/hostname-of-source.raq.com/
/home/sites/users/backup/hostname-of-source.raq.com.bak/

I need arround 1 GB to store these two versions (500 MB each).

6. Comments are welcome :-)

7. Here is the script:


#!/bin/sh
# raqbackup.sh 2.0 
# should work with CMU 1.x and CMU 2.x

# Local/Source Configuration

  SOURCE="hostname-of-source.raq.com"
  CMUEXPORT="/usr/sbin/cmuExport"
  MYSQLDUMP="/usr/local/mysql/bin/mysqldump"
  MYSQLPASS="passwordformysqlrootaccount"

# Target Configuration  

  TARGET="hostname-of-target.machine.com"
  TARGETUSER="backup"
  TARGETPASS="passworduserbackup"

# no need to change under this line

if [ -d /home/cmu/$SOURCE ]; then
  rm -rf /home/cmu/$SOURCE
  echo "$(date +%T) > last cmuExport deleted"
fi

if [ -f /home/cmu/cmuLog ]; then
  rm /home/cmu/cmuLog
  echo "$(date +%T) > logfile cmuLog deleted to have a fresh one"
fi

if [ -x $CMUEXPORT ]; then
  echo "$(date +%T) > starting cmuExport..."
  echo "******************************************************"
  $CMUEXPORT
  echo "******************************************************"
  echo "$(date +%T) > finished cmuExport!"
else
  echo "$(date +%T) > Error: $CMUEXPORT not found or not executeable"
  exit
fi

cd /home/cmu/$SOURCE


if [ -x $MYSQLDUMP ]; then
  echo "$(date +%T) > starting to dump mysql-databases..."
  $MYSQLDUMP --all-databases --add-locks -f -u root -p$MYSQLPASS > $SOURCE.mysqldump.sql
  echo "$(date +%T) > finished dumping to $SOURCE.mysqldump.sql!"
fi


echo "$(date +%T) > connect to $TARGET..."
echo "******************************************************"
ftp -i -n $TARGET  <<!EOF!
user $TARGETUSER $TARGETPASS

mkdir $SOURCE.bak
cd $SOURCE.bak
mdelete *
cd ..
rmdir $SOURCE.bak
rename $SOURCE $SOURCE.bak

mkdir $SOURCE
cd $SOURCE

ascii
put $SOURCE.mysqldump.sql
put backup.md5lst
mput *.xml

binary
mput *.gz

quit
!EOF!
echo "******************************************************"
echo "$(date +%T) > finished connection to $TARGET!"
echo "$(date +%T) > raqbackup.sh finished!"