lainard Posted August 27, 2007 Share Posted August 27, 2007 This is my backup Scripts!! which is wroking Smoothly Requirement! 1. Shell access 2. database username/password -=========================- Instruction -=========================- 1. Login to your Account using mysql user account! whatever (it will backup all mysql under this user privillede so do not use root) 2. Create backup database directory 3. Write or copy paste this bash script to your Home directory name it backup.sh #!/bin/bash MyUSER="mysql_username" # USERNAME MyPASS="mysql_password" # PASSWORD MyHOST="hostnameofyourmysql" # Hostname # If you are backing up your database from another server or your Home PC make sure you have already allowed wildcard Mysql hostname in cpanel account you can create it easy if you can find how to do it !google is your friend Backuser="linuxusername" # make sure username is correct or use root if you use root account # Linux bin paths, change this if it can't be autodetected via which command MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" CHOWN="$(which chown)" CHMOD="$(which chmod)" GZIP="$(which gzip)" # Backup Dest directory, change this if you have someother location DEST="/$Backuser" # Main directory where backup will be stored MBD="$DEST/mysql" # Get hostname HOST="$(hostname)" # Get data in dd-mm-yyyy format NOW="$(date +"%d-%m-%Y")" # File to store current backup file FILE="" # Store list of databases DBS="" # DO NOT BACKUP these databases IGGY="test" [ ! -d $MBD ] && mkdir -p $MBD || : # Only root can access it! $CHOWN 0.0 -R $DEST $CHMOD 0600 $DEST # Get all database list first DBS="$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')" for db in $DBS do skipdb=-1 if [ "$IGGY" != "" ]; then for i in $IGGY do [ "$db" == "$i" ] && skipdb=1 || : done fi if [ "$skipdb" == "-1" ] ; then FILE="$MBD/$db.$HOST.$NOW.gz" # do all inone job in pipe, # connect to mysql using mysqldump for select mysql database # and pipe it out to gz file in backup dir $MYSQLDUMP -u $MyUSER -h $MyHOST -p$MyPASS $db | $GZIP -9 > $FILE fi done 4. Save it 5. make cronjob according your need NOTE : i use below cronjob!! 0 12 * * * sh /root/backup.sh 0 Quote Link to comment Share on other sites More sharing options...
tracktor Posted August 27, 2007 Share Posted August 27, 2007 thanks for this, it is simple and work fine regards!! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.