CyberTek - the future at the present!
Google

Script to create mysql databases

Posted by: admin (Sep 21)

Today I am presenting a comfortable position to automate database saving nosri mysql database, in addition to the original script can be added at the end of the rescue and compression of individual databases in few lines the copy on a remote server and a message box in our report email.

#! / bin / bash
# Shell script to backup MySql database
# To backup databases Nysql files to / backup dir and later pick up by your
# Script. You can skip few databases from backup too.
# For more info please see (Installation info):
# Http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/01/mysql-backup-script.html
# Last updated: Aug - 2005
# -----------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2004, 2005 nixCraft project
# Feedback / comments / suggestions: http://cyberciti.biz/fb/
# -------------------------
# This script is part of nixCraft shell script collection (NSSC)
Visit # http://bash.cyberciti.biz/ for more information.
# Updated Sep - 2007 by CyberTek - http://www.cybertek.it
# -------------------------

Myuser = "SET-MYSQL-USER-NAME" # USERNAME
Mypass = "SET-PASSWORD" # PASSWORD
MyHOST = "localhost" # Hostname

# Linux bin paths, change this if it can not 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 = "/ backup"

# Main directory where backups 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
florence

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 $ - $ MyHOST h - p $ mypass $ db | $ GZIP - 9> $ FILE
florence

done

# Copy on remote server
echo'******************* Example_Backup *******************'> / root / mybackup.txt
echo \>> / root / mybackup.txt
date>> / root / mybackup.txt
echo \>> / root / mybackup.txt
'********************* Details *********************' echo>> / root / mybackup.txt
# remember that the scp command you can not specify the password if you have cleared a key on the target system
# otherwise you will have to do
scp / backup / mysql / * root@example.dom: / home / backup / example / mysql /
oh-ls / backup / mysql />> / root / mybackup.txt
echo'************************************************ * '>> / root / mybackup.txt
# send an email with the report of the work performed
mail-s "Example Backup" example@example.dom </ root / mybackup.txt

# remove after upload
rm-f / backup / mysql / *

  1. Giò Said,

    Ko, I have been very useful, thank you very much!

Add A Comment

Powered by CyberTek - Remote Assistance