Create MySQL-Backup Script and cleaner Script (only on one master)The backup script is created on one of the master databasesmaster database. In a redundant system, it must be done on the active master databse. The server creates a rolling backup and deletes backups which are older than 14 days. The cleaner script is also configured right after, to ensure that the two jobs do not run in parallel Note - this script will fail, if the jtel Databases JTELWeb, JTELStats, JTELStats2 and JTELLog are not present. Warning |
---|
title | Caution - without Replication |
---|
| If the setup is without replication, then remove -- mastersource -data =2 from from the backup script. |
Warning |
---|
| In Debian 11 Buster, a setting must be made in the config /lib/systemd/system/anacron.timer and the deamon/service must be reloaded. Code Block | vi /lib/systemd/system/anacron.timer
<OnCalendar=*-*-* 04..23:30>
systemctl daemon-reload
systemctl restart anacron.timer
systemctl status anacron.timer
Redundancy - Backup only on active DBM |
| Configure the backup on the active master database on redundant systems, as corruption of the index 'sp_AcdStatisticsLogin_geom3_AcdGroupsID' in the table JTELStats.AcdStatisticsLogin has happened in the past when the backup is made by the secondary database master. |
RUN AS ROOT: Status |
---|
colour | Red |
---|
title | Caution Password |
---|
|
Translations Ignore |
---|
Code Block |
---|
| # CONFIGURATION *** CHANGE PASSWORD ***
CONFIG_mysql_dump_username='root'
CONFIG_mysql_dump_password='<password>'
CONFIG_backup_dir='/home/jtel/shared/backup/sql'
CONFIG_mysql_dump_host='localhost'
# Create directories
cd /home/jtel
mkdir -p /home/jtel/jtelbackupjtel_dailyjobs
mkdir -p ${CONFIG_backup_dir}
# Create .my.cnf
cat << EOF > /home/jtel/.my.cnf
[client]
user = ${CONFIG_mysql_dump_username}
password = ${CONFIG_mysql_dump_password}
host = ${CONFIG_mysql_dump_host}
EOF
# Create backup script
cat << 'EOF' > /home/jtel/jtelbackup/jtelbackupjtel_dailyjobs/jtel_backup.sh
#!/bin/bash
mkdir -p /home/jtel/shared/backup/sql/daily
mysqldump --add-drop-database --single-transaction --mastersource-data=2 --add-drop-table --events --routines --triggers --databases JTELWeb JTELStats JTELStats2 JTELLog JTELCustomer | gzip > /home/jtel/shared/backup/sql/daily/backup-$(hostname)-database-$(date +%F-%H%M%S).sql.gz
find /home/jtel/shared/backup/sql/daily -type f -mtime +14 -delete
EOF
# Create croncleaner script
cat << 'EOF' > /home/jtel/jtelbackup/jtelbackupjtel_dailyjobs/jtel_cleaner.sh
#!/bin/bash
su - jtel -c 'bash /home/jtel/jtelbackup/jtelbackupshared/JTELCarrierPortal/DB/mySQL/cleaners/db_cleaner.sh'
EOF
# Execution permissions and cron job
chmod 750+x /home/jtel/jtelbackup/jtelbackup
chmod 750 /home/jtel/jtelbackup/jtelbackupjtel_dailyjobs/jtel_backup.sh
lnchmod -s+x /home/jtel/jtelbackup/jtelbackup /etc/cron.dailyjtel_dailyjobs/jtel_cleaner.sh
# Does Ownershipthe todailyjobs jtel user
chown -R jtel:jtel /home/jtel/.my.cnf
chown -R jtel:jtel /home/jtel/jtelbackup
chown -R jtel:jtel /home/jtel/shared/backup
# Run it
/etc/cron.daily/jtelbackup |
|
Once the script is run, a backup should be present in /home/jtel/shared/backup/sql/daily. The script runs automatically when the daily cron jobs are run. |