Difference between revisions of "Backup scripts"
From OpenKM Documentation
(→Remote backup with rsync) |
|||
(66 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | 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/. | + | {{TOCright}} __TOC__ |
+ | |||
+ | 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 [http://dar.linux.free.fr/doc/mini-howto/dar-differential-backup-mini-howto.es.html DAR differential backup mini-howto]. | ||
To install the cron job, run: | To install the cron job, run: | ||
Line 19: | Line 21: | ||
</source> | </source> | ||
− | + | {{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"> | ||
#!/bin/bash | #!/bin/bash | ||
# | # | ||
## BEGIN CONFIG ## | ## BEGIN CONFIG ## | ||
− | + | MYSQL_PASS="" | |
− | + | DATABASE_EXP="/home/openkm/db" | |
## END CONFIG ## | ## 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 | ||
+ | fi | ||
</source> | </source> | ||
− | + | This script will export all databases from a PostgreSQL installation: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<source lang="bash"> | <source lang="bash"> | ||
#!/bin/bash | #!/bin/bash | ||
# | # | ||
## BEGIN CONFIG ## | ## BEGIN CONFIG ## | ||
− | |||
− | |||
DATABASE_EXP="/home/openkm/db" | DATABASE_EXP="/home/openkm/db" | ||
− | |||
− | |||
## END CONFIG ## | ## END CONFIG ## | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
rm -rf $DATABASE_EXP | rm -rf $DATABASE_EXP | ||
mkdir -p $DATABASE_EXP | mkdir -p $DATABASE_EXP | ||
− | # | + | # Backup de PostgreSQL |
− | / | + | POSTGRESQL_DBS=$(su postgres -c "psql -l" | awk '(NR > 2) && (/[a-zA-Z0-9]+[ ]+[|]/) { print $1 }'); |
− | + | for DB in $POSTGRESQL_DBS ; do | |
− | + | if [[ $DB != "template0" && $DB != "template1" && $DB != "postgres" ]]; then | |
+ | echo "* Backuping PostgreSQL data from $DB..." | ||
+ | su postgres -c "pg_dump -Fc -b $DB" > $DATABASE_EXP/pg_$DB.dmp | ||
+ | fi | ||
done | done | ||
+ | </source> | ||
− | + | For more information take a look at [http://adminschoice.com/crontab-quick-reference Crontab quick reference] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | * [[Backup with LFTP]] | |
− | + | * [[Backup with rsync]] | |
− | + | * [[Backup with rdiff-backup]] | |
− | + | * [[Backup with duplicity]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
[[Category: Installation Guide]] | [[Category: Installation Guide]] | ||
− |
Latest revision as of 14:01, 10 March 2014
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
fi
This script will export all databases from a PostgreSQL installation:
#!/bin/bash
#
## BEGIN CONFIG ##
DATABASE_EXP="/home/openkm/db"
## END CONFIG ##
rm -rf $DATABASE_EXP
mkdir -p $DATABASE_EXP
# Backup de PostgreSQL
POSTGRESQL_DBS=$(su postgres -c "psql -l" | awk '(NR > 2) && (/[a-zA-Z0-9]+[ ]+[|]/) { print $1 }');
for DB in $POSTGRESQL_DBS ; do
if [[ $DB != "template0" && $DB != "template1" && $DB != "postgres" ]]; then
echo "* Backuping PostgreSQL data from $DB..."
su postgres -c "pg_dump -Fc -b $DB" > $DATABASE_EXP/pg_$DB.dmp
fi
done
For more information take a look at Crontab quick reference