Compile Xilinx EDK 8.1 Simulation Libraries in Ubuntu

March 29th, 2008

Installing Xilinx EDK in Ubuntu Linux is fairly easy, although it is 32-bit software but it still able to run flawless on my Ubuntu x86_64 machine. But everytime I compile the simulation libraries, the compilation just take few second. Wow, is this possible? No, the library path is empty!

I notice there is missing some library which is needed by EDK when compile simulation library. I run this command on my terminal:

compedklib -h

I will get this errors:

Simulation Library Compilation Wizard Xilinx EDK 8.1.02 Build EDK_I.20.4Copyright (c) 1995-2006 Xilinx, Inc.  All rights reserved.

xilperl: error while loading shared libraries: libdb-4.1.so: cannot open shared object file: No such file or directory

Hmm…I’m missing libdb-4-1.so object file in my lib32. So I start search this file in Ubuntu Packages Search and I can’t find any packages associate with it but have another package which may be suitable for me - ‘libdb4.2′. Next I start to use ‘getlibs’ to install it:

sudo getlibs -p libdb4.2
cd /usr/lib32/
sudo ln -sf libdb-4.2.so libdb-4.1.so

I rerun the EDK libraries compilation again….Wow, now I’m able to compile them!

Creative SB X-Fi Extreme Audio Sound Card in Ubuntu

March 7th, 2008

Last month my onboard sound card start being crazy, it work random after each shutdown. When I want to watch movies, I have to switch off my computer and turn on by hoping the onboard sound card work again. At first, I’m think this should be the drivers issues and my onboard sound card symptom do appear on this site. So I download the latest ALSA driver and I compile, but this can’t help.

Finally I can’t stand it anymore and bought Creative SB X-Fi Extreme Audio sound card to replace it. The old ALSA driver come with Ubuntu wouldn’t work with this card. I have to use the latest ALSA driver, you can download the driver from here. These are summary of this guide to compile and install the ALSA driver:

> tar jxf alsa-driver-xxx
> tar -xf alsa-driver-xxx
> cd alsa-driver-xxx
> ./configure --with-cards=ca0106 --with-sequencer=yes; make;
> sudo make install

Now restart your computer and the sound card should be working. If you need get the 5.1 surround work, you can edit your .asoundrc using editor you prefer(for original guide go here) :

	> vim .asoundrc

and add this in:

	pcm.!default {
	   type plug
	   slave.pcm "surround51"
	   slave.channels 6
	   route_policy duplicate
	}

Reference:

  1. Ubuntu HDA Intel HOWTO
  2. ALSA Module - CA0106
  3. Surround Sound in Linux
  4. The Simple Way to Get 5.1 Surround Sound Audio Working in Ubuntu

Install Microsoft Office 2003 using WINE

March 1st, 2008

Although all Linux distributors are coming with OpenOffice but no doubt Microsoft Office still is the most popular Office suite used by most peoples and companies. So some peoples might think they need Microsoft Office in their Linux machine as they already familiar with the Office interface. WINE need to be install, if you don’t know how please refer my guide to install WINE and IE6.

Next you need to configure WINE DLL override, enter this command:

> winecfg

this window will pop up :

Wine Configuration

Change the DLL overrides by click on “Libraries” tab

"advpack"="native, builtin"
"ole32"="builtin"
"oleaut32"="builtin"
"olepro32"="builtin"
"rpcrt4"="builtin"
"wininet"="builtin"

After setting is done, you can launch the installe:

> wine /path/to/office2003/setup.exe

and walla…the installer window shown :

Office2003 installer

Key in your license key, choose your path and program to install. The installation should finish without errors. To run the program:

> wine /path/to/wine/Microsoft\ Office/OFFICE11/WINWORD.EXE

Finally Microsoft Word 2003 in Linux:

MS Word 2003

Hope this small guide will help you all ;) BTW please make sure you have valid license for Microsoft Office before you start to install it. Don’t forget it not a open source software ;p

Ref:

  1. Running Ms Office 2003 under Linux with WINE 0.9.52

Microchip’s MPLAB IDE in Ubuntu Gusty

February 24th, 2008

Do you ever using Linux to develop PIC application? Unfortunately, Microchip don’t port their MPLAB to Linux platform in near future. But you still can use “WINE” to install MPLAB IDE on my Gusty machine, you can follow this guide for adding the APT repository. To install WINE on your machine:

> sudo apt-get update
> sudo apt-get install wine

next you will need IE6, go to this site download IEs4Linux and run the script:

> tar zxf ies4linux-<version>.tar.gz
> cd ies4linux-<version>
> ./ies4linux

EDIT: Adding a missing step which point out by Arpad Telse.

IEs4Linux will create its own WINEPREFILE under ~/.ies4linux/ie6, so you need to use this path as your WINEPREFIX when you install MPLAB. You either can replace your ~/.wine directory with ~/.ies4linux/ie6 or adding WINEPREFIX=”/home/<user>/.ies4linux/ie6″ in front of every wine command you enter, WINEPREFIX need a absolute to work. For example:

> WINEPREFIX=”/home/<user>/.ies4linux/ie6″ wincfg

From now on, I assume you have replace your ~/.wine with ~/.ies4linux/ie6.

You have to check the windows version of wine is set to windows 98:

> winecfg

winecfg

Next click on the “Libraries” tab to change DLL overrides:

"*msiexec.exe"="native"
"msi"="native"
"ole2"="native"
"ole32"="native, builtin"
"olepro32"="native, builtin"
"rpcrt4"="native"
"wininet"="native"

then run the installer

> wine /path/to/mplabinstaller/Install_MPLAB_v8.exe

The installer will start and pick any things you needed.

MPLAB installed

Finally MPLAB IDE launched:

MPLAB running

Xilinx iMPACT in Ubuntu Gusty x86_64

February 17th, 2008

After few day of install and customize my Gusty x86_64 desktop, I start to install ISE WebPack for my Xilinx Spartan3 development board. I’m able to install and run the 32-bit ISE flawless on my Gusty machine, but I think it may need to install 32-bit libs before install and running it. When I install ISE I already have 32-bit libs, so I’m don’t know whether it need or not ;p But it still is 32-bit software!! You can use this command to install 32-bit libs on 64-bit machine:

> sudo apt-get install ia32-libs

I start to lauch my ISE Webpack:

>  /path/to/xilinx/bin/ise

Yeah, it has launched success:

ise

Next I start to try out Xilinx iMPACT (Xilinx own JTAG programming software), I plug my parallel JTAG cable to Spartan3 board and switch on the power. When I start launch iMPACT , everything are fine. But the software keep complain it can’t find windrvr when it try detecting the cable. I’m wondering what is the windrvr is? Ohh… it is a propriety module from Jungo. Actually Xilinx have provide steps to install this module:

  • Download the file from the Xilinx ftp site to a local drive of the machine where the cable will be used.
  • extract it and run the install scrip:
> tar xzvf install_drivers.tar.gz
> cd install_drivers
> ./install_drivers
  • Change permissions on the USB / PC4 driver:
> chmod 666 /dev/windrvr

But I’m no luck, iMPACT can’t detect my cable after I installing windrvr. But I no give up, I continue google on the web and finally I come across to Sven-Åke Andersson’s blog. In his blog have some interesting topic on the iMPACT : XILINX JTAG tools on Linux without proprietary kernel modules. Wow… may be this the one ;p The blog have introduce me to a library call libusb-driver. It is use to emulates the module in userspace and allows the Xilinx tools to access the JTAG cable without the need for a proprietary kernel module ( indeed windrvr) - this is what explain from the official site.. Because I want to have the latest code so I clone the git to my own local drive:

> git clone git://git.zerfleddert.de/usb-driver
> cd usb-driver
> make

the output shown :

cc -Wall -fPIC -DUSB_DRIVER_VERSION="\"2008-02-16 14:22:48\""  usb-driver.c parport.c config.c jtagmon.c -o libusb-driver.so -ldl -lusb -lpthread -shared
cc -DDEBUG -Wall -fPIC -DUSB_DRIVER_VERSION="\"2008-02-16 14:22:48\""  usb-driver.c parport.c config.c jtagmon.c -o libusb-driver-DEBUG.so -ldl -lusb -lpthread -shared
Built library is 64 bit. Run `make lib32' to build a 32 bit version

Hmm…do I need to compile32-bit versio, I think I need. But why not give try first, may be 64-bit version is work for 32-bit ISE:

> LD_PRELOAD=/path/to/libusb-driver.so   /path/to/xilinx/ise

the ISE is start success but a error is shown in the terminal :

ERROR: ld.so: object '/opt/src/usb-driver/libusb-driver.so' from LD_PRELOAD cannot be preloaded: ignored.

and iMPACT still can’t detect my cable, so now I start to make a 32-bit libs:

> make lib32

now I can’t compile it :

make LIBVER=32 clean all
make[1]: Entering directory `/opt/src/usb-driver’
rm -f libusb-driver.so libusb-driver-DEBUG.so
cc -Wall -fPIC -DUSB_DRIVER_VERSION=”\”2008-02-16 14:22:48\”"  -m32 usb-driver.c parport.c config.c jtagmon.c -o libusb-driver.so -ldl -lusb -lpthread -shared
/usr/bin/ld: skipping incompatible /usr/bin/../lib/libusb.so when searching for -lusb
/usr/bin/ld: skipping incompatible /usr/bin/../lib/libusb.a when searching for -lusb
/usr/bin/ld: skipping incompatible /usr/lib/libusb.so when searching for -lusb
/usr/bin/ld: skipping incompatible /usr/lib/libusb.a when searching for -lusb
/usr/bin/ld: cannot find -lusb
collect2: ld returned 1 exit status
make[1]: *** [libusb-driver.so] Error 1
make[1]: Leaving directory `/opt/src/usb-driver’
make: *** [lib32] Error 2

Oh ya…the libusb is 64-bit version, so now I have to install a 32-bit version. How can I do that? May be ‘getlibs’ can help me, so I install the getlibs using step shown in Ubuntu Forum:

>  getlibs  libusb.so
libusb.so: libusb-dev
The following i386 packages will be installed:
libusb-dev
Continue [Y/n]? y

and I re-make again and I still have error saying :

/usr/bin/ld: skipping incompatible /usr/bin/../lib/libusb.so when searching for -lusb

So I download the libusb-0.1-4 from this Ubuntu package site, and manual extract to it and copy to /usr/lib32:

> dpkg -x  libusb-0.1-4_0.1.12-7_i386.deb
> cp  libusb-0.1.so.4* /usr/lib32
> make lib32

finally compilation success now ;) I’m so excited and start launch the iMPACT to try out the libusb-driver.so:

> LD_PRELOAD=/path/to/libusb-driver.so /path/to/xilinx/impact

Wah…Ii work!! iMPACT now able to detect my cable :

iMPACT launch

Next I try load bitstream file and program it to the FPGA:

iMPACT program

Program success!!!

Program Success

Ref :

  1. Gentoo : HOWTO Xilinx
  2. Sven-Åke Andersson’s blog: FPGA design from scratch. Part 25
  3. 9.2i iMPACT - Installing Xilinx cable drivers on Linux operating system/kernel version 2.4
  4. XILINX JTAG tools on Linux without proprietary kernel module

SDCC Plugin for MPLAB

July 8th, 2007

SDCC is a free and small C compiler for microcontroller, SDCC does support wide range of MCU including Intel 8051, Maxim 80DS390, Zilog Z80, Motorola 68HC08 and even Microchip PIC16/PIC18 series (although PIC still in development stage, but still can use SDCC to compile a working binary file ;p). For more information you can visit this page : http://sdcc.sourceforge.net/.

In last post, I do introduction how to compile the C code under batch mode, but for those windows users may not like the console syle :-P. As what I know most of PIC based are development under Microchip’s MPLAB (which only have Windows version). I don’t think is a good idea to ask those users switch to other IDE just to use SDCC, they may need time to familliar the environment (and most of them don’t have more support than MPLAB). What if there have a SDCC plugin for MPLAB? This idea come to my mind…and I start to search one for it, but I can’t find one. So I start plan to create one and I come across to this gputils-mplab (a GPUTILS plugin for MPLAB) when I searching how to create a MPLAB plugin.

Ohh…good, as least I have a good examples to refer to create my own SDCC-mplab (this is the plugin name I steal from gputil-mplab :-p). After I have done some experiment and study through the gputil-mplab source, finally I have create a simple SDCC plugin. Here is the executable file for my SDCC-mplab executable file ;) If you interesting on how I create the plugin you can down my source code from here. The program still have a lot bug, so you can use it without any warranty ;-p and I hope I can fix and improve it in the future.

Hope you guy can enjoy this plugin and do feedback to me ;)

Ref:

  1. SDCC main page
  2. GPUTILS -GNU PIC Utilities - main page for GPUTILS and you can find the gputils-mplab there.

Installing SDCC in Ubuntu Dapper

January 21st, 2007

Installing SDCC in Ubuntu is easy, you need this 2 line source.list to apt-get SDCC:

deb http://au.archive.ubuntu.com/ubuntu/ dapper universe
deb-src http://au.archive.ubuntu.com/ubuntu/ dapper universe

after have add this in source.list, just enter in command line and your SDCC will be installed:

sudo apt-get install sdcc

If you need a simulator, then you have enter:

sudo apt-get install sdcc-ucsim

The SDCC version you apt-get is the old revision, but I need the latest version to work on my project. So I will need to recompile from the source. Just go to this address to download the latest source and unzip it :

$tar -xvfz sdcc-src-xxx-xxx.tar.bz2
$cd sdcc
$./configure --prefix=/location
$make
$make install

The xxx-xxx is the version and revision of the SDCC source, ‘location’ can be any place. I put all my SDCC binary in /opt/sdcc. If compile succeed, these directories will be created:

/location/bin    - is for execute files
/location/share/sdcc/doc     - store documentation files
/location/share/sdcc/include - header files
/location/share/sdcc/lib       - libraries

You can test the SDCC with this simple code, create a test.c and vi it:


void main() {
}

To compile the code use this command:

sdcc test.c

If compilation is success a hex file will be create (depend on what cpu architecture compiled: test.ihx if MCS51 and test.hex if PIC). Here is the my simple makefile template use to compile my code:


INCLUDE=-I/opt/sdcc/share/sdcc/include/pic16
PROCESSOR_FLAG=-mpic16
CC=sdcc
AS=gpasm
CFLAGS=

HEX_FILES=a.hex

all: $(HEX_FILES)

##%.asm: %.c
%.hex: %.c
            $(CC) $(INCLUDE) $(PROCESSOR_FLAG) $(CFLAGS) $<

clean:
            $(RM) *.asm *.cod *.lst *.hex *.p *.d *.lnk *.o *~

You can modify what ever to suit for your project.

Sending Attachment Using Mutt and Sendmail

October 7th, 2006

After we have finish our wordpress backup script, we think it still not secure enough just to pust our backup DB at our own local disk. So mysurface come across a idea to send the backup file to a email. So I start coding a script to do the jobs for me, it just take few minute to code the complete code. But it take a 1-2 hours to search for information because i not familliar with the mail send in Linux. Here is the final version of the script:

#!/bin/sh
#
# sending the mysql backup file to gmail account

SUBJECT="Weekly MySQL Backup"
ADDRESS="Linux by Example<linuxbyexample@gmail.com>"
ATTACHMENT="/var/backups/wordpress/wp-bk-sql_6.sql.bz2"

if [ -e $ATTACHMENT ]
then
    echo "Sending MySQL backup file to "$ADDRESS" at "`date` > /tmp/backupmail
    cat /tmp/backupmail >> /var/log/backupmail.log
    mutt -s "$SUBJECT" -a "$ATTACHMENT" "$ADDRESS" < /tmp/backupmail
    rm -f /tmp/backupmail
fi

exit

I have put the script in my cron job, so that it will send out the mail once a week. This script is easy to understand, what it do is using the ‘mutt’ to send a attachment (the path shown in ATTACHMENT) to ADDRESS with subject - SUBJECT and the body is list in /tmp/backupmail. This script only work if your have a ‘mutt’ on your system. There have another way to send the attachment, here the code:

#!/bin/sh
#
# sending the mysql backup file to gmail account

myname="webmaster"
myaddr="root@lne.blgdns.com"
SUBJECT="Weekly Backup"
TO="Linux by Example"
ADDRESS="linuxbyexample@gmail.com"
ATTACHMENT="/var/backups/wordpress/wp-bk-sql_6.sql.bz2"
BODY="Weekly backup"

BOUNDARY=’=== This is the boundary between parts of the message. ===’
if [ -e $ATTACHMENT ]
then
    {
    echo "From: $myname <${myaddr}>"
    echo "To: $TO <${ADDRESS}>"
    echo ‘Subject:’ $SUBJECT
    echo ‘MIME-Version: 1.0′
    echo ‘Content-Type: MULTIPART/MIXED; ‘
    echo ‘    BOUNDARY=’\"$BOUNDARY\"
    echo
    echo ‘        This message is in MIME format.
    echo
    echo "–${BOUNDARY}"
    echo ‘Content-Type: TEXT/PLAIN; charset=US-ASCII’
    echo
    echo $BODY
    echo
    echo
    echo "–${BOUNDARY}"
    echo ‘Content-Type: application/x-bzip; name=’${ATTACHMENT}
    echo ‘Content-Transfer-Encoding: base64′
    echo ‘Content-Disposition: attachment;   filename=’${ATTACHMENT}
    echo
    uuencode -m $ATTACHMENT a | grep -v begin
    echo
    echo "–${BOUNDARY}–"
    } | /usr/sbin/sendmail $ADDRESS
    echo "Sending MySQL backup file to "$ADDRESS" at "`date` > /var/log/backupmail.log
fi

exit

This script just done the same job like the script about, just it have to add MIME Standard ("Multipurpose Internet Mail Extensions") and it just using sendmail to do the job!! You can also specifiy the content type for the attachment you want to send, in this example the type we want to send is bzip2. Another note is that you need the ‘uuencode’ to encode your binary file to a ASCII format. ‘-m’ switch used with uuencode is to encode the binary data with base64 which must consistent with the ‘Content-Transfer-Encoding’ which is base64. BODY is just the message you want send to receiver.

Ref :
1. Sending file as Mail Attachment
2. Sending email from Shell Script
3. Sending email with Attachment in UNIX System
4. Mail Question for HP-UNIX OS

continue to use vim, forget about learning emacs

August 20th, 2006

I was moved, when my friend show me how good Emacs is about. I try out Emacs, try to read up tutorials about Emacs. Emacs is a fancy tools, emacs support a lots of stuff, it allows you to read emails, news in emacs. Emacs allows you to do coding efficiently, auto indent, you can highlight the codes and indent it nicely, which it is one of the reasons I give Emacs a try. Emacs have a lots of mode, I can’t remember all and also not sure when I in which mode and when I in other. I just know when I in Emacs, I am out of control and I mess up everything.

For me, I just need a simple editor, editor that does editing / coding jobs and also I can customize features that I want to use, such as do shortcut key mapping, add in plugins which I like to have. Just like firefox, just like fluxbox, lightweigth but flexible. I find emacs too complecated, I don’t want to read news, mails, I just want to do some coding and scripting. I dislike the combo key of emacs. I have to press so much key to do a simple thing. Control something meta something, what the heck is meta man, alt. Again I can’t find a way to get tabview working in emacs. If you know, show me how.

Therefore I stop learning up emacs. On other hand, I look into what vim can do to fulfil my needs.

Bellow are my simple needs:

1. Auto indent
2. Auto complete
3. Tabs
4. Define own shortcut key
5. Syntax with different colors
6. Plugins to enable more features that I haven’t think of

Vim 7 can fulfil all my needs, maybe emacs also can, but vi is easy, available on every unix/linux/bsd. Not agree? show me with your emacs power. With a simple .vimrc in home directory, it works. I am still changing the .vimrc to makes my key map better to serve my humble needs. Bellow are my current .vimrc

” syntax color and scheme
syntax enable
colorscheme evening

” correct the backspace
set backspace=2

” indent and others plugin based on filetype
filetype plugin indent on

” indent setting
set smarttab autoindent
set tabstop=8
set expandtab
set sw=4

” turn of the highlighter by default
set hlsearch!

” key mapping
” tab navigation
:map :tabprevious
:map :tabnext
:map :tabnext
:map :tabnew .

” others
:map : set nu!
:map : set hlsearch!
:map : shell

” indent
:map ggv=

First two line, I enable syntax coloring, and also use a nice scheme, black background, white text. Migrate from vim 6 to vim 7, backspace becomes not functioning the way I want it, set backspace=2 fix that. filetype plugin indent on enable all the plugin and indentation base on different file format. You can check out what is the rules and how it set up the rules to make indentation and other plugins works at

/usr/share/vim/vim70

In this folder, contains couple of sub folders such as indent, plugins, syntax etc. Take a look at them, it is all scripts for vim. You can add more plugins, find more plugins and tips at the official website (http://www.vim.org/)

Next four lines is for indentation, tabstop is when you press tab at insert mode it leaves how many blanks, sw is the blanks it leaves when you do indentation. set hlsearch! is to highlights the keyword you select. I donno why by default it is turn on, I have no idea to turn it off elsewhere by default, so I did that at here.

Tab navigation is the best part which vim opens files into tabviews and I map the key for navigate between the tabs. set nu! is to toggle the line number besides the code for better reference. Without putting ! it works to enable, with ! it allows toggle. The last line is to do indentation for the source code. When I press F7, the source code will be indented nicely.

If you understand how the key mapping works, you can easily define your own key mapping. First of all, You have to understand vim have 3 simple modes ( maybe more, but I concentrate on 3 simple one)

1. Normal
2. Visual
3. Edit

When you in normal mode, which is the default mode, you cannot insert text, but you can navigate around, search for string to match, copy , cut and paste text. When you want to edit or insert text, you can type “i” ( without quote) in normal more and it will leads you to edit mode. After that if you want to return back to normal mode, you need to press ESC. Thats it you need to know for the mode switching. Visual mode is lessly use, it is when you want to highlight strings to perform copy (yank) or indentation. To enter visual mode, you press “v” (without quote) in normal mode. When you want to exit vim and save your file, you must first come back to normal mode, press ESC and type
“:x” (without quote, it is colon and character x)

Vim supports a lots of command when you are in the normal mode, one of them is to exit and save shows at above. Most of the commands start with “:”, key mapping is also start with “:”. You can do key mapping when your are using vim. The reason why we put all key maps into .vimrc is because you want it to run everytime you use vim. So “map” is a command, it uses to map a key to series of actions.

I map F6 to another command call hlsearch and it allows toggle with ! , CR is actually carry return, which is to execute the commands. So it becomes like this:

:map : set hlsearch!

Lets look at another example:

:map ggv=

I map F7 to do the list actions. They are press ESC to go back to normal mode in case it is at another mode. Then gg is to go to the first position of the opened file. v is to get in visual mode. S-g is Shift g which force the cursor to go to last line. This leads the entire file is selected, and last action =, performs the indentation.

The snapshot above is the console vim with tabviews.

By default if you open multiple files with vi, it will not open in tabs view, you need to do -p like

vim -p file1 file2 file3

Sometimes I may forget to type -p, seems I always like to open with tabviews, I can insert an alias to .bashrc

alias vi=”vim -p”

Next time when I type vi with list of filename, it will automatically open in tabs.

Auto Complete:
Another best feature of vim is auto complete, type to type something halfway and press Control p. It will list down all the possible words in list. This is useful when you are searching for the functions of c/c++. Okay, I know Emacs can do that too.

There are more plugins in http://www.vim.org including tetris game :smile:

Summary:
If you are vim user, and thinking of switching to Emacs or you already switched to emacs. Its time to come back for vim. If you are nano, gedit, kate user, I have an advice for you. Vim is not as simple as the editor you use, but it is not difficult to learn up compare to emacs. Give it a try, type vimtutor in your terminal. If you are windows user, don’t worry, go download gvim for windows, it works fine. If you are EMACS user, and read until this line, heh! I am glad you are still reading. Show me how EMACS can do better P:

Ref :
1. http://www.vim.org/
2. http://www.ukuug.org/events/linux2004/programme/paper-SMyers/Linux_2004_slides/vim_tips/
3. http://mysurface.no-ip.org/blog/?cat=15

wordpress backup script

August 1st, 2006

After my wordpress blog screw up, I realize one thing. I really have to backup my blog frequently. So I fire up my vim and write the scripts together with Liewsheng.

#!/bin/sh
todaydate=`date +%u`
longdate=`date +%m%d%Y`
ebkname="/var/backup/wordpress/wp-ebk-sql_$longdate.sql.bz2"
bkname2="/var/backup/wordpress/wp-bk-sql_$longdate.sql.bz2"
bkname="/var/backup/wordpress/wp-bk-sql_$todaydate.sql.bz2"

if [ -e $bkname ]
then
        filesize=`du -b $bkname | awk ‘ { print $1 }’`
fi

if [ ! -d "/var/backup/wordpress/" ]
then
        mkdir -p /var/backup/wordpress/
fi

mysqldump –add-drop-table -u ****** –database wordpress –password=****** | bzip2 -c > /tmp/wpsql

if [ `du -b /tmp/wpsql | awk ' { print $1 }'` -lt $filesize ]
then
         mv -f $bkname $ebkname
         echo "Emergency-Backup $ebkname "`date` >> /var/log/wpbk.log
fi

mv -f /tmp/wpsql $bkname
echo "Daily-Backup $bkname "`date` >> /var/log/wpbk.log

if [ $todaydate -eq 7 ]
then
        cp -f $bkname $bkname2
        echo "Weekly-Backup $bkname2 "`date` >> /var/log/wpbk.log
fi

exit

This can be consider a dirty coding, no comments at all. We need it fast and this is the one. We put this in /etc/cron.daily and restart crond service.

Okay I will briefly explain what my script have done. My script help us to do daily and weekly backup on wordpress database using mysqldump. It will backup 7 copy of database just in case anything goes wrong and it allows us to refers back. So if today is monday, it will backup as name "wp-ebk-sql_1.sql.bz2" and tuesday will be "wp-ebk-sql_2.sql.bz2" and until next week of monday, the file will be replace. This is daily backup. Every sunday, it will backup a copy with long date, that copy will stay permenently unless you delete it. This is weekly backup.

Another backup I called it as Emergency backup. Before I do daily backup, I ll check last weekday backup file. If it is exist, then compare the file size. If it’s file size is larger than new backup files, that means something wrong might already happen. Then I will not replace the file at first, I ll backup that file with long date and carry on the replacement.

Each time I do the backup, I will log it for reference.