DEPRICATED

Create MySQL-Backup  (Only one of the Masters)

The MySQL backup is created on the master server. The server performs daily backup and deletes all files older than 7 days.

Simply copy the following into the command line as root and execute it - replace <password> with the corresponding password:

CONFIG_mysql_dump_username='root'
CONFIG_mysql_dump_password='<password>'
CONFIG_backup_dir='/home/jtel/shared/backup/sql'
CONFIG_mysql_dump_host='localhost'
URI="http://downloads.sourceforge.net/project/automysqlbackup/AutoMySQLBackup/AutoMySQLBackup%20VER%203.0/automysqlbackup-v3.0_rc6.tar.gz"



cd /home/jtel
mkdir -p /home/jtel/automysqlbackup
mkdir -p ${CONFIG_backup_dir}
chown -R jtel:jtel /home/jtel/automysqlbackup
chown -R jtel:jtel /home/jtel/shared/backup

cd /home/jtel/automysqlbackup

curl -O -L ${URI}
tar xfvz ${URI##*/}

cp automysqlbackup.conf automysqlbackup.conf.orig
cp automysqlbackup automysqlbackup.orig


# remove parameter '--password' to fall back to .my.cnf
sed -i -e 's/--password="${CONFIG_mysql_dump_password}" //' automysqlbackup

cat << EOF > /home/jtel/.my.cnf
[client]
user = ${CONFIG_mysql_dump_username}
password = ${CONFIG_mysql_dump_password}
host = ${CONFIG_mysql_dump_host}
EOF
cat /home/jtel/.my.cnf


chown -R jtel:jtel /home/jtel/.my.cnf

cat << EOF > automysqlbackup.conf
CONFIG_mysql_dump_username="${CONFIG_mysql_dump_username}"
CONFIG_mysql_dump_password="${CONFIG_mysql_dump_password}"
CONFIG_mysql_dump_host="${CONFIG_mysql_dump_host}"
CONFIG_backup_dir="${CONFIG_backup_dir}"

# Include CREATE DATABASE in backup?
CONFIG_mysql_dump_create_database='yes'

# Separate backup directory and file for each DB? (yes or no)
CONFIG_mysql_dump_use_separate_dirs='no'

# Master Data
CONFIG_mysql_dump_master_data=2

# Single Transaction
CONFIG_mysql_dump_single_transaction='yes'

# List of databases for Daily/Weekly Backup e.g. ( 'DB1' 'DB2' 'DB3' ... )
# set to (), i.e. empty, if you want to backup all databases
#CONFIG_db_names=()

# List of databases for Monthly Backups.
# set to (), i.e. empty, if you want to backup all databases
#CONFIG_db_month_names=()

# List of DBNAMES to EXLUCDE if DBNAMES is empty, i.e. ().
CONFIG_db_exclude=( 'information_schema' 'performance_schema' )

# Include routines
CONFIG_mysql_dump_full_schema='yes'

# Rotation Settings

# Which day do you want monthly backups? (01 to 31)
# If the chosen day is greater than the last day of the month, it will be done
# on the last day of the month.
# Set to 0 to disable monthly backups.
#CONFIG_do_monthly="01"

# Which day do you want weekly backups? (1 to 7 where 1 is Monday)
# Set to 0 to disable weekly backups.
#CONFIG_do_weekly="5"

# Set rotation of daily backups. VALUE*24hours
# If you want to keep only today's backups, you could choose 1, i.e. everything older than 24hours will be removed.
#CONFIG_rotation_daily=6

# Set rotation for weekly backups. VALUE*24hours
#CONFIG_rotation_weekly=35

# Set rotation for monthly backups. VALUE*24hours
#CONFIG_rotation_monthly=150


# No SSL Connection to server
CONFIG_mysql_dump_usessl='no'
EOF


/home/jtel/automysqlbackup/automysqlbackup /home/jtel/automysqlbackup/automysqlbackup.conf
 
cat << 'EOF' > automysqlbackup.cron
#!/bin/bash
su - jtel -c '/home/jtel/automysqlbackup/automysqlbackup /home/jtel/automysqlbackup/automysqlbackup.conf'
EOF

chmod 750 automysqlbackup.cron
sudo ln -s /home/jtel/automysqlbackup/automysqlbackup.cron /etc/cron.daily
chown -R jtel:jtel /home/jtel/automysqlbackup
chown -R jtel:jtel /home/jtel/shared/backup


  • No labels