An easy way to backup databases
Just create a bash file:
#!/bin/bash
THEDBUSER="your_user"
THEDBPW="your_pass"
THEPATH="/opt/your/backups/path"
create_backup()
{
THEDATE=`date +%Y%m%d%H%M`
mysqldump \
--skip-c omments \
--routines \
-u $THEDBUSER \
-p${THEDBPW} \
$1 \
| gzip > ${THEPATH}/dbbackup_${1}_${THEDATE}.bak.gz
}
create_backup "your_db"
create_backup "your_other_db"
create_backup "another_db"
find ${THEPATH}* -mtime +5 -delete
Then just add it to the cron jobs crontab -e
0 12 * * * /opt/your/backups/path/make_backup.sh
Written by Alecs Galindo
Related protips
2 Responses
if you use mysqldump, do it with --quick at least
over 1 year ago
·
@mikhailov hm, interesting, didn't know about that option!
--quick, -q
The docs say:
This option is useful for dumping large tables. It forces mysqldump to retrieve rows for a table from the server a row at a time rather than retrieving the entire row set and buffering it in memory before writing it out.
So for "small" databases (< available RAM I guess) it would be faster to go without that option, as all the rows would be read out at once?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mysql
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#