Mobil Mewah

Salah satu sumber Inspirasi.

Mobil Sport terbaik

Anda pasti bisa memilikinya.

Bermain dengan pesawat

Salah satu ide yang gila, Balapan di udara.

Bermain di angkasa

Apakah ini salah satu Goals dalam hidup anda? anda pasti bisa mencapainya

Tuesday 17 December 2013

Repair WIndows 7 MBR boot record

I have Windows 7 installation, and try to dual boot with FreeBSD 9. Then problem occurs and fail to create the BSD. and then the Windows 7 cannot boot either. The windows partition is still not touched, but cannot boot to windows.

So the question was how to repair the Windows 7 Master Boot Record (MBR) ?

After search on google, there are solution to repair it using the windows 7 instalation disk.

Here are the step done and documented :

1. Boot to the Windows 7 installation disk


2.  Select the Install Now


3. Select the recovery mode


 4. Select the command prompt options.


5. Then you got some msdos prompt like :
    x:\windows\system32>
6. Then type :  dispkart  and press enter
7. Type : select disk 0  and press enter
8. Type : list volume and press enter
9.There will be a list of volume, search for your windows 7 cdrom drive letter.
10. Then type :  exit  and press enter
11. Then go to your windows 7 dvd drive , if it is g then go to g: by type G: and then enter
12. Then type  cd boot
13. Then to restore your MBR do this :
       bootsect /nt60 SYS /mbr  and press enter
14. Then you will be informed about the BOOTMGR volume update.
15. Then exit the msdos, and reboot/ restart.

Don't forget eject your DVD, and your windows7 will be boot and can be use again.

Welcome back to the windows.


Wednesday 4 December 2013

Linux in usb pen drive

Linux is a very powerfull Operating System, and USB pen drive now days are very cheap and affordable with bigger size every year.

What you can do with the old USB pen drive which you have since the day 1 you use USB pen drive, let say the 1 GB USB pen drive you have. To small for storing your image and music files right ?

But don't keep your USB pen drive in the store room. You can use your old USB to boot a Linux Operating System. Yes you can even with minimal 1 GB size of USB pen drive.

You can install many Linux Distro, like Ubuntu , Damn small Linux (50Mb ISO) and many others Linux distros you can have.

This time, we use Linux Damn Small Linux distros and install it in USB pen Drive. To install to USB, we can use windows as the host. Download the tools here and get your ISO files from Damn Small Linux website.

The DSL linux version used was DSL-4.4.10 , download around 50Mb to your local drive, then install using the tools to install to USB pen drive.

Then change your booting preference in the BIOS to enable boot to USB pen drive. But you also can boot the DSL in windows, just read the readme file provided after the installation finish.

Here are the screen shoot of the DSL linux Desktop.

DSL Linux
DSL Linux Desktop




Django error when doing insert

Django error when doing insert
What is the cause of error like this in django + postgresql application :

DatabaseError: current transaction is aborted, commands ignored until end of transaction block

What happen was I import a production database to my development database. Then there are some south migration that not running locally. I found in forum, the problem maybe with the migration or syncdb.

But all already checked, same error still happen when insert to table.

Then check the sql log, the Aha moment was raised, the problem with the table was no value for ID fields which should be auto increment or serial type in postgresql.

So alter the table field and change it to serial type. Then the error was gone.

So the problem was with the table fields. Check your sql log with this type of error. You will find the problem there.


Tuesday 3 December 2013

Postgresql backup and restore

When doing some development, we need a fast backup and restore for database data in postgresql server.

The package provide an easy way to do the backup and restore in 1 command.

You only need the username and password + the database name to be working on.

Here are the backup command signature :


Backup : $pg_dump -U {user-name} {source_db} -f {dumpfile.sql}

Restore: $psql -U {user-name} -d {destination_db} -f {dumpfile.sql}

So this command is straighforward. I dump a 1000 records in 5 seconds.

Also note that the privilege and db owner is follow in the dump file. You must prepare the exact username and database, with no table in it.
This is because the generated dump database not include a drop table command.


But how if we want to backup all database ? Of course we can do it to.

Backup all postgres databases :

We can backup all databases in postgres using pg_dumpall command .

To do the backup run this command :

$pg_dumpall > all.sql


We also can verify if all database is backed up using a grep command :


$grep "^[\]connect" all.sql
\connect blog
\connect facebook
\connect mytweet

What if we want to backup a specific postgres table ? hell yeah you can .

Backup a specific postgres table

The command are :


$pg_dump --table production -U acongbebo -f onlyproduction.sql


Postgresql is a powerfull database you can imagine. support for GIS database already included.

Monday 2 December 2013

Postgresql DB Initialization in FreeBSD

Here are some command that used for administrating postgresql database.

The OS being use was FreeBSD9.1 with postgresql 8.3 


TO enable postgresql service add this in /etc/rc.conf :

postgresql_enable=”Yes”

postgresql_data=”/usr/local/pgsql/data”

postgresql_flags=”-w –s –m fast”

postgresql_initdb_flags=”—encoding=utf-8 –lc-collate=C”

postgresql_class=”default”



To install init db :

#/usr/local/etc/rc.d/postgresql initdb



We don’t have root user and a user in freebsd, so create one.

#su pgsql

#createuser dba    [set as
superuser]

Then change password :

#psql postgres dba

postgres=# ALTER
USER dba WITH PASSWORD ‘newpass’;

To create database :

#createdb mydb –o acong

[o] is owner of db

There we are. The database mydb ready to use and access from local host only.

Later on how to do backup and restore in Postgresql fast.

cacti time problem

Yesterday, I have a migration for may cacti NMS server from one Virtual Machine to other Virtual Machine. The problem is that the time error when the VM migrated.

This make the graph cannot be updated by the cacti pooler.

The time is shifted forward 3 years. If only 24 hours shift, we can just wait for the 24 hours time difference. But 3 years, its unsusable. So the solution is only delete all rrd data and crso bad, create from scratch.

This is so bad, as I don't have any backup. Last 1 year performance history data was gone.

This is bad with cacti, if only had a protection to stop the rra being updated by the pooler when time is shifting to far away.

I don't know if this can be happen with other monitoring tools like zabbix or zennos.

I like to use zabbix, but the setup to much and I have no time to try it out.

Lesson learned with CACTI :

  1. Backup your RRA data once every week
  2. Stop the pooler work when do some migration and time changing routine
  3. Always make sure you have backup.
Hope you can learn from this experience also.

Sunday 1 December 2013

Upgrading Django 1.3 to 1.6 road blocks

Upgrade Django 1.3 to 1.6
So I try to upgrade my project to use Django 1.6 .

What I found is some setting that change, and to specific to note in the django Documentation. So I make notes on what have change and need to adjust in my django app configuration.

manage.py

The manage.py files. Now start from Django 1.4 there was a major change. One of the aim was to overcome the double import file in python.

The recommended manage.py are :

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ p_name }}.settings")
  from django.core.management import execute_from_command_line
  execute_from_command_line(sys.argv)

Here you change the {{ p_name }} to your project folder. And the manage.py should be move up one level of the project folder.

So the layout should be :

project
|--Blogs
   |-- urls.py
   |-- settings.py
   |-- models.py
   |-- views.py
|-- manage.py

urls.py

The urls.py import change. In Django1.3 we use :

from django.conf.urls.defaults import patterns, include, url
Now starting Django 1.4 there were no more defaults in urls. So we change to :

from django.conf.urls import patterns, include, url

To make it compatible with previous version of Django1.4 you can use try block :

try:
  from django.conf.urls.defaults import patterns, include, url # django1.3 support
except:
  from django.conf.urls import patterns, include, url


settings.py

If you implement the resusable app concept, your settings will have some application level configuration variable in the project settings.py which you can access from application via settings.import . But after Django1.4 all change. 

If your application need access configuration variable in settings.py , this what you should change:

from settings import RESULTS_PER_PAGE , SITE_NAME, SITE_DESCRIPTION

To new way :

from django.conf import settings
  RESULTS_PER_PAGE = settings.RESULTS_PER_PAGE
  SITE_NAME = settings.SITE_NAME
  SITE_DESCRIPTION = settings.SITE_DESCRIPTION

if you want to keep compatibility with < Django1.4 :

try:
  from settings import RESULTS_PER_PAGE , SITE_NAME, SITE_DESCRIPTION
except:
  from django.conf import settings
  RESULTS_PER_PAGE = settings.RESULTS_PER_PAGE
  SITE_NAME = settings.SITE_NAME
  SITE_DESCRIPTION = settings.SITE_DESCRIPTION

And another thing to change in settings.py in TEMPLATE_CONTEXT_PROCESSOR section :

# old
TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth",
                              
)
# new
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
                               
)


So the change I found out only :

  1. Manage.py file location
    This change the whole config and directory layout of a project
  2. URLS import in urls.py
    No more django.conf.urls.defaults , change to django.conf.urls
  3. Import Settings Variable
    Need other way to import settings variable. What I learn that any reusable app should not depends on the project settings.This give a loose app and project relationship.
And the result, I bumped with more configuration that had to change, like the context processor utils?
I decide to roll back, and better use the new Django1.6 with new project anyway.

And maybe should upgrade 1.3 to 1.4 first.

Updates :

I try again and bumped with the context processor utils, the problem was the django.conf import. I use import settings for load all the default knob in my application, now i use :

from django.conf import settings  

Now my apps run in django 1.4 . Next will be upgrade to django 1.5 and I will posting my findings.

Django Version 1.6 release

Recently Django released Django 1.6 release in 6 November 2013. While I am still using Django 1.3 in my production server.

Looks so many improvement and site layout arrangement in newer version and make the temptation to try it out.

I have the options to upgrade to the newer version. But what makes me stop is there are to many change in the process. Maybe better to use the newer version with new project because the layout is changes to much.

In my deployment and development, I use the Reuse application methodology. So i hope the change is only in the project layout, but the app layout is still the same.

What I encounter in Django 1.3 lack of is, the sql batch insert. In one of my project, I need to update many rows at once, and the ORM doing update to database one at a time.

In Django 1.4 there is sql batch insert functionality which is good news.

And in Django 1.6 that I read from realese notes, the update are :

  • SQL persistance connection
  • Admin interface activated by default
  • Change in Django Transaction Handling
  • Discovery of test in any test module
  • Support BinaryField in model field
  • Model.save() algorithm changed
    This minimize the queries sent to sql server to 1 command only, before 2 sql command when save is called
For the Details you can see in the Release Notes of Django sites.

Twitter Delicious Facebook Digg Stumbleupon Favorites More