Simple bash script to backup database and web server directory aka ezi bakup

I wrote this script long time ago and released its 1st version v0.1 with very initial setup in mind. After that i haven’t got time to look into the code and enhance it further. But today i am going to announce the 2nd version v0.2 with new features plus easy to setup params file. Detailed error description are added to the code for better output. A separate params.ini file to change the settings, so it will be not needed to touch the code if you are not familiar with it. Just setup the params.ini file and you are good to go. As usual it will backup the database and directory you want it to backup for you in your desired location(local system). Even can run it under cron to create backup for you let’s say once a day or a week, that depends on your needs. I will explain the params.ini file in details so you get an idea, how it will work. The archive will include readme.txt, params.ini and ezi_bakup.sh files. readme.txt will contain some basic setup and details about the script. params.ini will contain the settings and ezi_bakup.sh is the meat which will do what you tell it via params.ini.

ezi_backup_output

How to use(params.ini):

[cc lang=”bash” escaped=”true” nowrap=”false” noborder=”true” line_numbers=”true” lines=”10″ tab_size=”4″]
bkdrbool=FALSE
dbbool=TRUE
dbusername=root
dbpassword=
dbname=test
stgdir=/backup/
bakdir=/var/www/test_project

[/cc]

Line 1: set to true if want to backup web server or any dir, TRUE = create, FALSE = skip

Line 2: set to true for database backup, TRUE = create, FALSE = skip

Line 3,4: Database Username and password

Line 5: Database Name

Line 6: Storage/backup directory, where you want to backup your files

Line 7: Directory to create backup of

Cron sample setup:

This will run the script every day at 11PM with a log file created to output log events. Please change the path to the script.

[cc lang=”bash” escaped=”true” nowrap=”false” noborder=”true” line_numbers=”true” lines=”2″ tab_size=”4″]

0 23 * * * /backup/bash/ezi_bakup.sh >> /backup/bash/cron.log 2>&1

[/cc]

Updates:
– Future updates will be directly pushed to bitbucket repository, keep eye on the repository for new features and updates.
– Repository: https://bitbucket.org/mmarif4u/ezi-bakup/

Download:
– Clone the repository. OR
Download it as archive by clicking on the branches tab.

Got any issues with it, feel free to report a bug/issue here.

Simple bash script: Backup www directory and MySQL database

Update (30-08-2013): New version is available.

Hi all,

I had written a simple bash script, which is still in very basic shape. I planned to release it in a version cycle. The basic goal is to create backup of mentioned directories. I am working on it to improve it and release further revisions of it. The script is capable of:

1- Backup the mentioned directory(in this case www) with tar.gz compression.

2- Backup MySQL mentioned database with compression.

There are just few changes you need to do, because its the early version so i need to improve it more and more. Also you can setup it up under cron to run it on specified time and create backup automatically. I will guide here step by step what changes need to make and how to setup it under cron.

cd /Documents/

In the above line, one need to change the directory where the backup files will be stored. Can create directory in home and give the path here.

INPUTDIR=”/Assignments/”

Change the above to your www directory, which maybe in /var/ or in /srv/.

mysqldump -uroot -ppassword –opt database_name > database_backup_$(date +%Y%m%d).sql

In the above line, you need to change the database username, password and  database name.

And you are almost done till here.

Now lets automate this script in cron to create backup of the selected directories at midnight every day.

0 0 * * * sh  /home/user/backup_0.1.sh

For more about cron… here.

Download script