DB dump with chroot

I caught chroot first time when attempting to install gentoo linux. Of course, its a tool of great useful. Two months ago I had my laptop crashed, and all static files were recovery easily by copy while raw db data file seems to be difficult to handle.

The old file system is in a mobile disk, mounted at /media/disk-1/. Now I try to use chroot to rollback to that environment, so that all standard dump tools will be available.

Before you chroot to the system, don’t forget to bind /dev to new location. Or you might get error prompt such as “/dev/null Permission Denied” (it’s a common error). Just execute command below:
$ sudo mount –bind /dev /media/disk-1/dev

Then change root to my old system:
$ sudo chroot /media/disk-1

Now you become root user automatically.

MySQL Dump

In a standard ubuntu mysql installation, we should launch mysql db from init.d by:
# /etc/init.d/mysql start

But it’s no longer available in such environment. Fortunately, there is a direct way:
# mysqld_safe &

OK, go on to dump database with mysqldump:
# mysqldump –all-databases > mysql_dump_file

Postgresql Dump

We cannot use init.d to start pgsql either. Therefore, try to run it by:
# su postgres -c “/usr/lib/postgresql/8.3/bin/pg_ctl start -D /etc/postgresql/8.3/main”

/etc/postgresql/8.3/main is the default data directory in standard installation(with apt-get). This directory is supposed to contain a file named with “postgesql.conf”

Now pgsql db is also running. As root user we have no privilege to run pgsql utilities. so take following steps:
# touch pgsql_dump_file
# chmod a+w pgsql_dump_file
# su postgres -c “pg_dumpall -f pgsql_dump_file”

Conclusion

Personally, I found it’s too complex and low efficiency to backup and restore data with mysql and postgresql. If there is no critical requirement(just like personal data management), file based db(Surely I mean sqlite) is no doubt better choice. Easy management(lots of gui tool now provided), smooth copy and move, standard db interface for programming, and enough functionality.

[旧]Up and Running: PostgreSQL and PostGIS on Ubuntu 8.10, Step By Step

每次安装pgsql的过程都是这么震撼人心。以下在Ubuntu 8.10上安装配置运行pgsql及postgis的简单步骤。和Windows相比,用apt-get安装不会再有服务安装不上的问题,但是可能会有包装不全、缺少配置的问题。

首先用apt-get下载安装pgsql和postgis的需要的包

sudo apt-get install postgresql-8.3 postgresql-8.3-postgis postgresql-client-8.3 postgresql-contrib-8.3 pgadmin3

安装过程中会提示创建一个默认名为postgres的用户。

安装结束后,启动pgsql服务器

sudo /etc/init.d/postgresql-8.3 start

在默认情况下pgsql ident的设置为postgres用户用ident sameuser的方式登录,这种方式类似于sqlserver使用windows的用户管理。因此要用postgres用户登录系统。

修改postgres用户的密码

sudo passwd postgres

用新密码登录为postgres

su – postgres

运行psql,可以检查pgsql的运行情况

psql

可以在psql中给postgres用户设置数据库密码

ALTER USER postgres ENCRYPTED PASSWORD ‘yournewpassword’;

继续在psql中创建plsql语言。如果安装时遗漏了contrib包这一步是不能完成的。

CREATE LANGUAGE plsql;

退出psql,创建Postgis数据库。

createdb postgis

导入postgis的两个sql文件,其中定义了EPSG数据库和Geometry类型。

psql -d postgis -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql
psql -d postgis -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql

进入psql对当前用户GRAND ALL

GRANT ALL ON TABLE geometry_columns TO postgres;
GRANT ALL ON TABLE spatial_ref_sys TO postgres;

这样做的结果是这两张表被导入到默认的postgres数据库中。这样今后创建postgis数据库就可以以postgres为template_db,不过这么做的后果是这两张表的owner都是postgres。在GeoServer里创建FeatureType时必须用postgres用户登录,否则权限不足。

这时PostGIS应该可以正常工作了,可以尝试导入shp

shp2pgsql /your/shp/file tablename | psql newgisdb

创建一个新的数据库用户

createuser -p username

修改/etc/postgresql/8.3/main/pg_hda.conf,设置数据库访问的认证方式

将local all all一行的验证方式(method)由ident sameuser改为password就可以用密码登录psql了,在python-psycopg中用新建的用户连接pgsql也不会报ident失败了。

将host all 127.0.0.1/32一行的验证方式也改为password就可以在本地用jdbc以用户名密码连接数据库了。

Opera-mini

偌大的互联网,却找不到一个带提交按钮的文本框。

昨天为了能看一眼facebook上的留言(汗,其实我对翻墙的要求也够低的)可谓无所不用其极。首先是用tor+privoxy,结果tor的速度实在是太慢,除了tor的测试页面其它根本就打不开。然后看到了ssh -D的方法,这个速度也是很慢,但是不小心打开了twitter.com,然后又海枯石烂地登录成功,看到没有新的direct msg,也就算达到目的了。

再后来就看到opera-mini的在线DEMO,一个j2me simulator,借助这个applet可以顺顺利利地打开facebook twiiter之类的网站,但是因为Linux上JRE中文字体的问题,看起来多少还有点吃力。然后我就弱弱地睡下来,片刻之后才反应过来这一切多有意思。看看Opera-mini最大的卖点:

http://en.wikipedia.org/wiki/Opera_Mini#Functionality

在Server和终端之间有一个Proxy,这个Proxy整好运行在墙外面,也就不奇怪twitter facebook这样的网站可以轻松地访问了。不仅仅是在线demo,用手机终端也是一样的道理。我之前还一直以为是中移动的疏忽,看来真是错怪他们的工作了,呵呵。

http://en.wikipedia.org/wiki/Opera_Mini#Functionality

张江深处

我都不好意思跟人说我去了上海,因为我很快就要窝在张江这么个村不村镇不镇的地方了。也说不清是好是坏,远离闹市中心倒是求得清静;但是真住在陌生城市最边缘的地方心里倒是一阵失落,还要花着血汗钱养活黑心的房东,我这是干什么来了。以上是例行的牢骚,我也无力阻止它的生成。好在有像WG和Samson这样的好友,讨论一下大家的处境,虽然也不会有什么具体的变化,但是心态总能相对缓和一些。嗨,生活就这个样子了,关键在你怎么看待它。

饭否这下恐怕真是没了,离了饭否,又是极大的空虚和不安以及痛心。不出意外的话,这事的起因又是针对时事的言论传播。我是保守人士,对于很多肆无忌惮地甚至就是具有挑逗性的言论其实非常反感。不怕被骂,我时常感受到这一代粪青内心和大脑的空虚,通过传播一些具有挑逗性(实则极度干瘪老套)的言论获得一些挑战“常规”的隐隐快感。这群人称为“不明真相的群众”实在是恰如其分。

看出来了吧,我确实边缘了,住到边缘的地方也是罪有应得。

我还是希望饭否能恢复,为了让我抢救出一些重要的对话留作纪念。

Pylons Tips

All scripts created by paster(paster create, paster controller and etc.) uses 4 spaces as indent while many editors(vim) uses tabs automatically. Different indent in one file will cause fatal error.

h.url_for is a popular helper function in many books and tutorials which to solve url mapping. This tool is no longer available by default since 0.97. If you got error message like “AttributeError: ‘module’ object has no attribute ‘url_for’”, just add

[codesyntax lang="python"]from routes import url_for[/codesyntax]
to yourapp/libs/helper.py .