skip navigation

www.Hilands.com


Content:: Shell - SQL Backup

Shell - SQL Backup

This is a simple shell script to backup your MySQL Database. It uses mysqldump a simple date variable and stores the output in a file.

Usage
# ./sqlbackup.sh
Change the permissions to allow execution of the file if need be.
# chmod 775 sqlbackup.sh
Setting up a cron job to run every day at 3:00 am
   0  3    * * *   root    /opt/scripts/sqlbackup.sh


The Code
#!/bin/sh
################################################################################
# File Name : sqlbackup.sh                                                     #
# Author(s) :                                                                  #
#   Phil Allen <phil@hilands.com>                                              #
# Last Edited By :                                                             #
#   phil@hilands.com                                                           #
# Version : 2009101300                                                         #
#                                                                              #
# Copyright information                                                        #
#                                                                              #
# Copyright (C) 2009 Phil Allen <phil@hilands.com>                             #
#                                                                              #
# This file is free software; you can redistribute it and/or modify            #
# it under the terms of the GNU General Public License as published by         #
# the Free Software Foundation; version 2 of the License.                      #
#                                                                              #
# This program is distributed in the hope that it will be useful,              #
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
# GNU General Public License for more details.                                 #
#                                                                              #
# You should have received a copy of the GNU General Public License            #
# along with this program or from the site that you downloaded it              #
# from; if not, write to the Free Software Foundation, Inc., 59 Temple         #
# Place, Suite 330, Boston, MA  02111-1307   USA                               #
#                                                                              #
# General Information (algorithm) :                                            #
#   Script will access the mysqldump program and dump the files to the         #
#   you tell it to. Running this script on a cron job is recommended           #
#   0  3    * * *   root    /opt/scripts/sqlbackup.sh                          #
#                                                                              #
################################################################################
DATE=`date +%Y%m%d` ;
/usr/local/mysql/bin/mysqldump -a -u <user> -p<password> <database> > file.$DATE.sql


sqlbackup.tgz
Download 895 bytes
MD5 - c94138375b55253343ba085f9c983859 *sqlbackup.tgz
Last Modified: 2012-10-21