Tuesday, June 23, 2015

How to Automate MySQL Backup - Ubuntu

Recently i want to backup some MySQL Database  to this i have used Automysqlbackup tool.
this tool backup the Databases daily weekly and Monthly.

  • To Install the automysqlbackup
         # sudo apt-get install automysqlbackup
  • Start the Service
        # sudo automysqlbackup
  • Config Files are stored in /etc/default/automysqlbackup
       # sudo nano /etc/default/automysqlbackup
  •  uncomment the Following Lines. 
Note : From this it will create a seprate folders daly , weekly , Monthly and have separate folders for DB in /var/lib/automysqlbackup.

 # Username to access the MySQL server e.g. dbuser
USERNAME=`grep user /etc/mysql/debian.cnf | tail -n 1 | cut -d"=" -f2 | awk '{print $1}'`
# Username to access the MySQL server e.g. password
PASSWORD=`grep password /etc/mysql/debian.cnf | tail -n 1 | cut -d"=" -f2 | awk '{print $1}'`

# Host name (or IP address) of MySQL server e.g localhost
DBHOST=localhost

# reading the mysql folder content. Feel free to replace by something else.
DBNAMES=`find /var/lib/mysql -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f5 | grep -v ^mysql\$ | tr \\\r\\\n ,\ `

# This one does a list of dbs using a MySQL statement.

DBNAMES=`mysql --defaults-file=/etc/mysql/debian.cnf --execute="SHOW DATABASES" | awk '{print $1}' | grep -v ^Database$ | grep -v ^mysql$ | grep -v ^performance_schema$ | grep -v ^information_schema$ | tr \\\r\\\n ,\ `

# root, with Unix rights 0600.
BACKUPDIR="/var/lib/automysqlbackup"

# List of DBBNAMES for Monthly Backups.
MDBNAMES="mysql $dbname "

0 comments:

Post a Comment