Welcome to the Linux Foundation Forum!

[useful] MySQL datbase backup script

lenswipe Posts: 2

Here is a script i use for backing my website up. Its a simple shell scipt that runs the mysql dump command.

mysqldump -udatabaseusername
databasename >$(date).sql

so a typical usage of this might be:


mysqldump -uroot -pajellydoghnut

database1 >$(date).sql


Where root is the username, ajellydoughnut is

the password and database1 is the database i

want to backup.

The advantage to doing it this way is that i can

go ahead and add this script as a cron joob to be

executed say every Tuesday at 11am meaning

that my database is backed up automatically for

me and a backup of that database is downloaded

to wherever this script is stored in .sql format

(typically i put it in a folder of its own in my

home directory)

Another handy thing is that because

of >$(date).sql on the end the script automatically

sets the current date and time as the filename

meaning no more messing around looking

through the creation time, its just there in the

filename :)

Hope this helps someone.



  • s7s
    s7s Posts: 1

    FN='/bin/date +%Y-%m-%d'
    PARAM="--quote-names --add-drop-table -u$USER -p$PSW"

    cd $BK_DIR
    mysqldump ${PARAM} trac > trac.sql
    mysqldump ${PARAM} zabbix > zabbix.sql

    tar -cvf mysql_$(date +%d.%m.%y).tar *.sql
    gzip mysql_$(date +%d.%m.%y).tar
    chmod 600 ${BK_DIR}/mysql_$(date +%d.%m.%y).tar.gz
  • lenswipe
    lenswipe Posts: 2
    is ther an adantage to doing it that way?
  • aarrieta
    aarrieta Posts: 2
    yes. I guess portability is one big advantage with this last one. You can use it in another server just changing the variables. Also, its a complete script (#!/bin/sh....)


Upcoming Training