Backup
Table of contents
Script to backup one certain MySQL database
#!/bin/sh
GZIP="/usr/bin/gzip"
DATO=`date "+%d"`
TIME=`date "+%H"`
DATOTIME="${DATO}_${TIME}"
USER="username"
PASS="password"
BASE="database"
FILE="/home/user/backup/db/databse_$DATOTIME.sql"
FLAGS="-u $USER --password=$PASS -c --create-options -e $BASE"
/usr/bin/nice -10 /usr/local/bin/mysqldump $FLAGS > $FILE
/usr/bin/nice -10 $GZIP -f $FILE
if [ "$TIME" -eq "00" ]; then
/usr/bin/nice -10 /usr/local/bin/rsync -q -e "ssh -p 22" -av $FILE.gz user@domain:/home/user/backup/db/databse_$DATOTIME.sql.gz
fiAnd the crontab to go with it
10 */1 * * * /bin/runlock backup-db /home/avizion/bin/backup-db.sh
This will backup the database to local disk every hour, and the midnight copy will also be sent to a remote host for further archiving and security measures.
Please note that the /bin/runlock utility is a custom script of mine.
- + : A leading plus sign indicates that this word must be present in every object returned.
- - : A leading minus sign indicates that this word must not be present in any row returned.
- By default (when neither plus nor minus is specified) the word is optional, but the object that contain it will be rated higher.
- < > : These two operators are used to change a word's contribution to the relevance value that is assigned to a row.
- ( ) : Parentheses are used to group words into subexpressions.
- ~ : A leading tilde acts as a negation operator, causing the word's contribution to the object relevance to be negative. It's useful for marking noise words. An object that contains such a word will be rated lower than others, but will not be excluded altogether, as it would be with the - operator.
- * : An asterisk is the truncation operator. Unlike the other operators, it should be appended to the word, not prepended.
- " : The phrase, that is enclosed in double quotes ", matches only objects that contain this phrase literally, as it was typed.
