my new mysqlbackup script
this way I backup my mysql databases:
(My old one was bigger and written in php.)
(My old one was bigger and written in php.)
#!/bin/sh
# this script should have access to /root/.my.cnf
export USER=root
export HOME=/root
# get date YYYYMMDD
DATE=`date +%Y%m%d`
# where is the mysql's datadir
DATADIR=`/usr/bin/mysqladmin variables | grep datadir | awk '{print $4}'`
# search for all databases
DATABASES=`cd $DATADIR && find * -type d`
# work dir
WDIR="/home/backup/"
# destination folder/location for backup
DST="SOMEUSER@SOMEHOST:/SOMEPATH/mysql/"
# path to mysqlhotcopy
MYSQLHOTCOPY=/usr/bin/mysqlhotcopy
# create a temp folder
mkdir $WDIR$DATE
# hotcopy all databases
for DATABASE in $DATABASES
do
$MYSQLHOTCOPY -q $DATABASE $WDIR$DATE/
done
# tar all hotcopies
cd $WDIR
tar -zcf mysql_$DATE.tgz $DATE/
# copy backup
cd $WDIR
scp mysql_$DATE.tgz $DST
# clean up tempfiles
cd $WDIR
rm -rf $DATE
rm mysql_$DATE.tgz
Kommentare
Keine (weiteren) neuen Kommentare erlaubt.
