Jump to content

MySQL Backup -> Ftp Script


Guest lillecarl

Recommended Posts

Hello, well i have picked together a bash script (yes damn its for linux, windows users should go get a linux box :))

Basically it does backup all databases the mysql user you run the script under can access (so if you for example just wanna backup char database then only allow the user to access the char database)

I think yall can read what it does... so no need for me to explain that rly? :) Anyways here is the code.

#!/bin/bash
### apt-get install mysql-client ncftp
### MySQL Server Login Info ###
MUSER="mangos"
MPASS="mangos"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
BAK="/home/mangos/backup"
GZIP="$(which gzip)"
### FTP SERVER Login info ###
FTPU="ftpuser"
FTPP="ftppass"
FTPS="fptsrvr"
NOW=$(date +"%d-%m-%Y")

[ ! -d $BAK ] && mkdir -p $BAK || /bin/rm -f $BAK/*
echo MySQL Database dumping initialized
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
if [ "$db" != "information_schema" ]; then
 echo Started dumping $db
 FILE=$BAK/$NOW-$(date +"%T").$db.gz
 $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
 echo Finished dumping $db
fi
done
echo Finished dumping, will now begin ftp transfer to $FTPS
ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF
mkdir $NOW
cd $NOW
lcd $BAK
mput *
quit
EOF
echo MySQL database backups finished

Packages needed are bash, mysql-client and ncftp

PS: I would like to know all people with "big" servers, do you use replications to backup or how do you do it exactly?:)

- LilleCarl

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use