3 easy steps for scheduling regular backup of your MySql database: Be safe


Apart from my previous article on safety features ,it is a well known fact , that it is extremely important to take backup of your MySql database of your live website.


Just follow below 3 steps and everything is under control :

Step 1: Configure backup directory on server

mkdir /var/lib/mysqlbackup
cd /var/lib/mysqlbackup


Step 2: Make the backup script

    vi dbbackup.sh


Paste the content as below and change the username, password and dbname as required

# Username to access the MySQL server
# Username to access the MySQL server
# List of DBNAMES for Backup
#date timestamp for log message
DATE=`/bin/date +%Y-%m-%d_%Hh%Mm`
#output file
#working directory
#cd $DIR
# MySQL Backup
/usr/bin/mysqldump --database $DBNAME --opt --single-transaction -u$USERNAME -p$PASSWORD | /usr/bin/gzip -9 > $OUTDIR$OUTFILE


Change the permission of backup script

chmod +x dbbackup.sh


Step3: Schedule the backup script in crontab

crontab -e


Add below like to take backup everyday at 3.20 pm

20 15 * * * /var/lib/mysqlbackup/dbbackup.sh


All done!

  • February 14, 2010
8 Best Free Stock Video Websites for Tiktok, Reels, and Shorts Top 5 PHP Frameworks: Fast and Secure