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.
惊现pr=5
你现在可以昂首挺胸说自己是互联网主力信息生产者了
@WG 我这是承了烧饭和samson的衣钵,现在用EN来写技术blog,造福/祸害全世界人民。
哎,那个PR=4的停滞不前的时代总算过去了,从PR的角度来说,我大学思念真是没有长进,俺高三的个人主页就PR4了啊
你的意思,EN写的技术帖就能让博客上5?
靠,我不会说英语咋办……
@WG 看淡之,PR都是浮云,自己写着乐呵就好
以前我写Blog是鞭策自己每天做点事情,现在写blog是追求心灵的放松和满足|||||||
好吧……
人生要看淡,才能有所收获
@WG 在我如此严肃的一篇EN技术贴下面居然讨论人生,哎
因为一切都与人生相关啊……
人生啊……
ps,为啥我的验证码老是implements……
@WG 我如今不是transient就是synchronized,你那个已经不错了,还是samson的方法好,验证码不爽就刷一下吧|||||