Jump to content
Sign in to follow this  

Cron Jobs Backup

Recommended Posts



I'm add this contribution simple because I use it.

This script already on my computer for ages and I got it from another place. But since the original author not mentioned on the script, so I can not said who is he/she. :(

The credit should go to "John Doe" or "Jane Doe", not me.


The contribution uploaded at:


Edited by midave

Share this post

Link to post
Share on other sites

i think there is a mistake:


case ($size>=1024); $size = round($size/1024) . " KB"; break;

should be

case ($size>=1024): $size = round($size/1024) . " KB"; break;

Share this post

Link to post
Share on other sites

here's an improved script...maybe :) got some trouble on my server using your script. the base of this script i found on the internet (long time ago) too and did some modifcations.


KEEP=31 # number of backups to keep
USER='user' # database user
PASS='pass' # database password
DB='db' # select the database to backup, or... 
#DB='--all-databases' # backup all databases (comment the line above)
BUPATH='/root/backup_etkatalog/db_backups' # path to this (!!) script

BACKUPS=`find $BUPATH -name $DB"-*.sql.gz" | wc -l | sed 's/\ //g'` 
while [ $BACKUPS -ge $KEEP ]
ls -tr1 $BUPATH/$DB-*.sql.gz | head -n 1 | xargs rm -f 
BACKUPS=`expr $BACKUPS - 1` 
DATE=`date +%Y%m%d%H%M%S`
rm -f $BUPATH/.$DB-${DATE}.sql.gz_TMP
/usr/bin/mysqldump $DB --opt -Q -u$USER -p$PASS | gzip -c -9 > $BUPATH/.$DB-${DATE}.sql.gz_TMP
mv -f $BUPATH/.$DB-${DATE}.sql.gz_TMP $BUPATH/$DB-${DATE}.sql.gz
exit 0 

# example for daily backup (00:01)
# ================================
# add this line to crontab
# 1 0 * * * root sh /path/to/this/script.sh

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this