Shell-Skript, um tägliches DB-Backup (für etwas wie Redmine, etc) aufzunehmen - mysql, bash, shell, backup, redmine

Benötigen Sie eine Skriptlösung, um täglich eine Datenbank zu sichern und eine Mail zu senden.

Der Code erstellt eine Sicherungskopie für mysql DB und die beteiligten Dateien (wie in den meisten Anwendungsfällen)

Antworten:

0 für die Antwort № 1
#!/bin/bash
cat /dev/null > Body.text
DATE=`date +%b/%d/%Y`
BACKUP_DIR="/home/user/Redmine/tmp"
DB_NAME="xxx"
DB_USER="xxx"
DB_PASSWORD="XXXXXX"
Redmine_Root="/home/webuser/apps/redmine"
echo "Redmine Backup Directory is $BACKUP_DIR" >> /root/Body.text
rm -rf $BACKUP_DIR/files* $BACKUP_DIR/Redmine*

# -- MySQL
echo "`date` at Redmine"s MySQL db Backup on" >> /root/Body.text
mysqldump -u $DB_USER  -p$DB_PASSWORD $DB_NAME > $BACKUP_DIR/Redmine.sql
gzip $BACKUP_DIR/Redmine.sql
rm -f $BACKUP_DIR/Redmine.sql

#........Redmine
echo "`date` at REDMINE_Files Backup " >> /root/Body.text

#Create back up for Files
echo "Backing up Redmine attachments..."
rsync -a $Redmine_Root/files/ $BACKUP_DIR/files/

echo "Packing into single archive redmine files"
tar -zcvf $BACKUP_DIR/redminefiles.tar $BACKUP_DIR/files
rm -rf $BACKUP_DIR/files/

#Create a single tar file
echo "Create Backup of Single File" >> /root/Body.text
cd /home/user/Redmine
tar -cvf Redmine`date +%b%d%y`.tar tmp/
tar -cvf /home/user/Redmine`date +%d%b%y`.tar /home/user/Redmine/tmp
rm -f $BACKUP_DIR/redminefiles* $BACKUP_DIR/Redmine*
rm -f $BACKUP_DIR/Redmine.sql.gz

#Cleaning Up
echo "Delete five days olderbackup" >> /root/Body.text
find /home/maitreya/Redmine/* -mtime +5 -exec rm -rf {} ;

#Sending Report
/usr/bin/mutt -e "set realname=" Redmine-Backup"  "     -s "Redmine Backup on $DATE" [email protected] -c [email protected] < /root/Body.text