How To: using bash script to backup MySql

Create a file backup_db.sh, and paste the following contents:

#get the first parameter as the database name
DATABASE=$1

#if no database specified, then you can set the default one
if [ -z $DATABASE ]; then
    DATABASE=default_database_name_here
fi

#mysql user and password to backup the database.
MYSQLUSER=mysql_user
MYSQLPWD=mysql_password
    
#path to backup
ARCHIVEPATH=~/backup/db_backup
DATE=`date +%Y%m%d`
YEAR=`date +%Y`
MONTH=`date +%m`
FOLDER_MONTH=$ARCHIVEPATH/$YEAR$MONTH
    
if [ ! -d $FOLDER_MONTH ]; then
    echo "mkdir $FOLDER_MONTH"
    mkdir $FOLDER_MONTH
fi
    
# Backup
echo "mysqldump -u$MYSQLUSER -p$MYSQLPWD $DATABASE | gzip $FOLDER_MONTH/$DATABASE-$DATE.sql.gz"
mysqldump -u$MYSQLUSER -p$MYSQLPWD $DATABASE | gzip $FOLDER_MONTH/$DATABASE-$DATE.sql.gz

and you can add the script to cron job under *nix and schedule under windows:

*nix:

Save the following text in file: db_backup.at

10 * * * * ~/backup/backup_db.sh databasename

and call

crontab db_backup.at

You need to change the period to run the script for your business, e.g. each day, each week etc.

Add two ips to one NIC in ubuntu

edit file: /etc/network/interfaces

the original content should be something like:

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.5
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
    
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 192.168.0.1

add the following settings in the file:

auto eth0:1
iface eth0:1 inet static
address 192.168.0.6
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1

# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 192.168.0.1

run command in root mode:

/etc/init.d/networking restart

that’s all. you can run ifconfig to check if it works.

I had tested it under ubuntu 6.10.