Difference between revisions of "Backup scripts"
From OpenKM Documentation
Line 22: | Line 22: | ||
{{Note|MAILTO may also be used to direct mail to multiple recipients by separating recipient users with a comma.}} | {{Note|MAILTO may also be used to direct mail to multiple recipients by separating recipient users with a comma.}} | ||
+ | |||
+ | This script will export all databases from a MySQL installation: | ||
<source lang="bash"> | <source lang="bash"> |
Revision as of 13:59, 14 November 2012
These backup scripts use rsync to minimize network load and creates incremental backups, preserving last four backups. For more info, read http://www.mikerubel.org/computers/rsync_snapshots/. Also recommend the article DAR differential backup mini-howto.
To install the cron job, run:
$ sudo crontab -e
And add these lines according to your personal configuration:
MAILTO=nomail@openkm.com
@weekly /root/backup.sh | tee -a /root/backup.log
Or, if you want to separate log reports by date:
MAILTO=nomail@openkm.com
@weekly /root/backup.sh | tee /root/backup.$(date +\%Y.\%m.\%d_\%H.\%M.\%S).log
MAILTO may also be used to direct mail to multiple recipients by separating recipient users with a comma. |
This script will export all databases from a MySQL installation:
#!/bin/bash
#
## BEGIN CONFIG ##
MYSQL_PASS=""
DATABASE_EXP="/home/openkm/db"
## END CONFIG ##
rm -rf $DATABASE_EXP
mkdir -p $DATABASE_EXP
# Backup de MySQL
if [ -n "$MYSQL_PASS" ]; then
MYSQL_DBS=$(mysqlshow -h localhost -u root -p$MYSQL_PASS | awk '(NR > 2) && (/[a-zA-Z0-9]+[ ]+[|]/) { print $2 }');
for DB in $MYSQL_DBS; do
if [[ $DB != "mysql" && $DB != "test" && $DB != "information_schema" && $DB != "performance_schema" ]]; then
echo "* Backuping MySQL data from $DB..."
mysqldump -h localhost -u root -p$MYSQL_PASS $DB > $DATABASE_EXP/mysql_$DB.sql
fi
done
echo "-------------------------------------";
fi
For more information take a look at Crontab quick reference