Beyond the Sky

The place where surface stop and share the experience of life

Archive: July 2006

wordpress daily backup

, ,

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.

My wordpress blog gone sad

I just writting this blog for 3 dayz, today morning wake up and discover that its all gone, donno what happen....

I got this:

404 Page Not Found

There's been a problem finding the page you're looking for. Apologies. Perhaps . . .

* the page your looking for was moved;
* your referring site gave you an incorrect address; or
* something went terribly wrong.

Use the search box and see if you can't find what you're looking for.

and this

Categories

WordPress database error: [Table 'wp_categories' is marked as crashed and should be repaired]
SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, category_count FROM wp_categories WHERE cat_ID > 0 ORDER BY cat_name asc

This is worse!!! The problem is I donno what happen.

Install OpenBox for cygwin

, , , ...

First of all, I was quite amazed when I saw KDE, GNOME can be install at cygwin. devil I am going to turn my office Windows box into LINUX ( somehow ... ) Okay, actually I search for fluxbox, but I can only find openbox and it is old version.

Anyway, I just wanna try how powerful of cygwin on X11. So I run setup.exe at c:\cygwin and check openbox, which it automatically solves all dependencies for me. To run openbox, I need to create a file and run initx.

echo "exec openbox" > ~/.xinitrc
initx


TaDa bigsmile

Okay, at that moment I found a very interesting page http://www.cs.wcupa.edu/~rkline/cygwin-install.html
Which shows you the way to actually open linux X-packages which store at other linux box.
Simple steps:
1. Type xinit [ This will initiate X server and openbox is start ]
2. Right click the open xterm.
3. Type ssh -Y username@ip-addr
4. Once you login with password, then run any packages you have, for let say gaim &

It is a bit slow, but gaim is loaded and run like you have install that in the local machine.

Access to PC in LAN after login to ssh server under cygwin

, , , ...

I spend the entire day figure out how to do that, after successfully installed sshd and cygwin on windows XP. To read about how to setup SSH server on windows box, please refers back http://my.opera.com/mysurface/blog/show.dml/372169

To login to others PC by specifing IP, username and password. You need to use msdos command which is NET USE. First of all my command is correct, but it couldn't works. Bellow shows the usage and example I can obtain at internet and also cygwin mailing list.

NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[domainname\]username]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [/SMARTCARD]
        [/SAVECRED]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]


Examples:
 NET USE \\192.168.1.10\documents /USER:neo neospasswd 

With putting like this, it would not work and given error message like :
 System error 67 has occurred.
The network name cannot be found. 

Searching through the mailing list and some forum, it gives me all silly solutions which it doesn't work at all, such as mount manually, etc. And some of them stated in the mailing list that they giving up and just treat it doesn't work at all. Finally I found the solution, i have to put single quote within the IP address like this
 NET USE '\\192.168.1.10\documents' /USER:neo neospasswd 


I have to put password as the last argument, which I do not feel so confortable. By right, without specifying any password, it will prompt you from type in the password, some how it doesn't work that way. So It is time to apply bash shell script which i had learn for so far. To make it flexible, I had write a simple one.

#!/bin/sh

#Get the info I want, password will not display
read -r -p "IP or Server Name to login (ig \\\\ip-addr\\target-dir): " name
echo $name
read -p "Drive to MAP : ( A - Z): " drive
read -p "Login: " login
read -s -p "Password: " passwd

#UnMap the drive, i have no idea how to check this.
#Therefore, I just run this everytime
net use /delete $drive":"

#construct the command and run it.
str="net use $drive: '$name' /user:$login $passwd"
eval $str

if [ $? == 0 ]
then
        echo "The drive will be in /cygdrive "
        echo
        exit 0
fi


Install SSH server to your Windows Box.

, ,

If you have windows installed and switch on 24 seven, and you feel that you want to copy files or manipulate files remotely and even access to the LAN networks. If you want to have remote desktop to windows box, then you may consider VNC. If you familier with ssh and scp and are not interested in using GUI, then you would like to read this futher.

You have no problem to connect to any linux server, ssh client putty is a very lightweight tools for you. But if you want to setup ssh server at windows, a very first thing you need is CYGWIN. Cygwin is a software that support various POSIX based packages and tools that originally running on (Linux, BSDs) to run at windows. The first time I heard about cygwin is last 2 years when I want to setup Network Simulator 2.26. At that time, cygwin is very difficult to setup but today, cygwin becomes very easy.


Steps to setup Cygwin and ssh:

1. Login as administrator or user with admin privilege.
2. Make sure all users have set password, check control panel -> user account. Set password for all users, logout and login again.
3. create a folder to store all packages c:\cygwin
4. Download setup.exe, click http://www.cygwin.com/setup.exe and save it to c:\cygwin
5. Run it and click next next next, pick a mirror and continue until you see selections menu.
6. Click view button until is shows Full view.
7. Search for OpenSSH and vim, or other packages you like to include with. Basically OpenSSH would be enough, you can install other packages later by running setup.exe again.
[Installation will take sometimes to download ... ]
8. Right click My Computer -> Properties -> Advanced -> Environment Variables
9. At System variable , click NEW button, enter variable name "CYGWIN" and value "ntsec".
10. Select the Path variable and click the EDIT button.
11. Append ;c:\cygwin\bin to the end of the existing variable string.
12. Okay, now can start cygwin, double click the icon.
13. Type ssh-host-config
14. Say "yes" to privilege separation, create local user sshd and install sshd as a service.
15. When the script stops and asks you for "CYGWIN=" type ntsec
16. Type net start sshd
17. Okay if you want to create more user accounts, please do so and then open cygwin again and
18. Type mkpasswd --local > /etc/passwd
19. Type mkgroup --local > /etc/group
20. Okay you are done, take any ssh client and try it out. you c: is at /cygdrive/c



Do not forgot that SSH uses port 22, so you need to add exception port 22 at windows firewall.

Click Start...Control Panel....Security Centre....Manage Security Settings for Windows Firewall....Exceptions tab....Add Port...
"Name of port" is ssh "Port number" is 22 (check the "TCP" checkbox)



For details please check out this page http://www.chinese-watercolor.com/LRP/printsrv/cygwin-sshd.html

Next comming up, I am going to write on how to access LAN networks with using net use and also performs remote desktop to linux box with openbox under cygwin.

Free GPL Desktop Dictionary - StarDict

, , ,

There are plenty of free dictionary website, my favourite site is www.onelook.com. Why would I want to install a desktop dictionary? Stardict have provide few features which worth spend time to install and try.

1. Support multiple dictionaries at once, dictionaries of the user's choice are installed separately. There are plenty of dictionary files available for download at http://stardict.sourceforge.net/Dictionaries.php It includes other foreign language dictionary such as English to Chinese, French to Chinese, English to French etc. It also contains dictionaries that explains words in specific area such as science, medical, computer etc.

2. Scan mode that allow easy lookup. By default scan mode is enabled. With scan mode, to check for meaning, user can double click on a word or highlight the words. Stardict will pop up a context menu with all the results.

3. Stardict allow fuzzy query. With Fuzzy Query, user allow to enter the query word with wildcards. Stardict will list all the available words which meets the query with wildcards. This allow users search for the word even he do not know the correct spelling.

There are other's features yet to discover. With these features, stardict is worth install package.

Compile and upgrade the latest fluxbox 1.0rc2 to FC5

, ,

I searching for latest fluxbox 1.0rc2 RPM, but I couldn't find any. So I decided to compile myself. Special thanks to _mark at #fluxbox at irc.freenode.net for clearing my doubts on Fluxbox configuration and compilation.

To upgrade to the latest version, the best way is remove the old rpm and make install from new source code. I couldn't do that because my GDM will complain it couldn't find exec line for fluxbox and it refused to load fluxbox. I have no idea to fix it. So the workaround is replace the binaries directly from the source code.

Compilation:
In order to support png icon at root menu, you need to enable imlib2. By default fluxbox will be installed to /usr/local, for me, my fluxbox is in /usr/bin instead of /usr/local/bin. So what I need to do is.

1. Get imlib2-devel, this is the header that needed by compilation.
2. Configure it with imlib2 enabled and set prefix to /usr
3. make and make install by root privilege.

yum install imlib2-devel
./configure --prefix=/usr --enable-imlib2
make
make install


Done.

Monitor internet traffic of other Windows XP machine using MRTG

,

To monitor any machine including routers, if you have to make sure the machine have support SNMP protocol. Well, Windows XP have SNMP service.

Install SNMP service:
1. Goto Control Panel, Add and remove Programs, select tab "Add and Remove Windows Components"
2. Check "Management and Monitoring tools.

The service will be auto start after installation done. To configure the SNMP service, goto control panel, administration tools and click on service. You can find SNMP service at there. I do not configure anything, the default community key is "public"

Now I have to configure my linux box where MRTG was installed.

1. Create another configuration files to point to Windows XP. Assume XP machine IP address is 192.168.1.2.
cd /etc/mrtg
cfgmaker public@192.168.1.2 > mrtg2.cfg


2. Recreate the Index page.
indexmaker -title 'My MRTG' -output /var/www/html/mrtg/index.html /etc/mrtg/{mrtg.cfg,mrtg2.cfg}


3. Add another entry to crontab
*/5 * * * * root /usr/bin/mrtg /etc/mrtg/mrtg2.cfg


4. Restart crond deamon
service crond restart 


Done. Before you do all these steps, you may want to check whether you can receive snmp packets from XP machine or not. So you can use snmpwalk for that. Assume the machine IP is 192.168.1.2
snmpwalk -v 1 -c public 192.168.1.2 interface


If you get timeout, probably your firewall blocks the SNMP port, open port UDP and TCP of 161.
-A RH-Firewall-1-INPUT -p tcp --dport 161 -d 192.168.1.2 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 161 -d 192.168.1.2 -j ACCEPT

Setup MRTG

,

The Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network links. NTOP doesn't shows the in and out traffic separately, I would like to see my in and out traffic clearly so I setup MRTG. Setup MRTG is not a "simple" task. My defination of simple is yum install or apt-get install it and ready for use.

For setting up MRTG, you need some steps. First talks about dependency, install all the packages listed as bellow:

net-snmp                       
net-snmp-libs
net-snmp-utils
mrtg


Yum or apt-get it all. Verify what you have, you must have mrtg folder at /var/www. For my case my working html folder is at /var/www/html. so first thing I do is:
mv /var/www/mrtg /var/www/html


Configure /etc/snmp/snmpd.conf, add in the community key you enter, you gonna use it later.
rocommunity public

For this case, "public" is your community key.

chkconfig snmpd on

Keep in mind if you use ubuntu or debian based distro, change the entry of K50snmpd to K50snmpd at /etc/rc2. ( rc? depend on you startup id you used, check first few line of /etc/initab

Start snmp service
service snmpd start
or
sudo /etc/init.d/snmpd start 


Check whether snmp is is working, try few times.
snmpwalk -v 1 -c public localhost interface

Replace with your community key if you have specified other name.

Configure MRTG, if have existing mrtg.cfg backup it
cd /etc/mrtg
cfgmaker public@192.168.1.1 > mrtg.cfg

Assume public is community key and 192.168.1.1 is your IP address. This command with create a simple mrtg configuration file, change the working directory.
vi mrtg.cfg

Check this line
WorkDir: /var/www/html/mrtg


Create a nice index.html for mrtg.
indexmaker -title 'My MRTG' -output /var/www/html/mrtg/index.html /etc/mrtg/mrtg.cfg

Almost done, set crontab now.
[CODE]vi /etc/crontab

Addin this line:
*/5 * * * * root /usr/bin/mrtg /etc/mrtg/mrtg.cfg 


This makes crontab service run this line every 5 minutes and update the graph. Restart crontab and you are done.
 service crond restart
or
 sudo /etc/init.d/crond restart 


Now go http://localhost/mrtg and check out.


Special thanks to Simon Teh from NRG USM guiding me on setup MRTG on my home machine.

Setup NS2.29 on FC5

,

There are issues on OTCL/TCL/TK which will cause your configuration fail in the middle. I found the patch from the mailing list ( http://www.archivesat.com/post1272327.htm ) After applying the patch, it work as expected.

In case you facing problem installing on FC5 and found no solution, you can follow the simple instruction here.

1. Download ns-allinone-2.29 from the website, extract it at either home directory or opt
2. Download the patch from ns2292-gcc410.patch
3. Copy the patch into ns-allinone-2.29 folder and patch it with:
patch -p1 < ns2292-gcc410.patch


In case it was not working, don't throw the question to me, you will get no solution from me . Throw it back the ns2 mailing list. As I am trying to help here, but I am not expert of this, Good Luck.