tag:blogger.com,1999:blog-2062249881040649402024-03-08T07:52:07.431+01:00chris goes xpeXtreme Programming, soft, life, etc.Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-206224988104064940.post-11630166953894988972019-02-25T12:17:00.001+01:002019-02-25T12:19:27.558+01:00Android (Oreo) moving files workaround (TAR archive) with preserving time stampThe issue in Android is that while copying/moving files to other location a new timestamp is created (details can be found here: https://forum.xda-developers.com/android/general/guide-timestamp-attributes-correct-t2960935)<br />
<br />
The workaround that works for me is using tar in Terminal or adb while connected to your computer.<br />
<br />
example:<br />
I have pictures in internal sdcard (internal memory on my phone) and would like to free up this space moving to external sd card. Regular copy/move creates for them new timestamp (filenames are still the same, so sorting on filenames helps but only if all the files have the same naming convention)<br />
<br />
workaround (using adb):<br />
<span style="font-family: inherit;">-- to see if your phone is detected</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">$ adb devices</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">List of devices attached</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">* daemon not running; starting now at tcp:5037</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">* daemon started successfully</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">ad0617021484e0aaed<span style="white-space: pre;"> </span>device</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: inherit;">-- connect to your phone's shell and change into DCIM folder with </span><span style="font-family: inherit;">internal photos from camera</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">$ adb shell</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">herolte:/ $ cd /sdcard/DCIM/ </span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: inherit;">-- get location of your external sd card</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">herolte:/sdcard/DCIM $ ls /storage/ </span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>0000-0000</b> Private emulated enc_emulated self</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: inherit;">-- prepare tar archive on external sd card in below location with name zzz_jpg.tar holding all jpg files</span><br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">$ tar cvf /storage/0000-0000/DCIM/Camera/zzz_jpg.tar *jpg</span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;"><br /></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: inherit;">-- this will delete all jpg files that were put into tar archive (you can do that as last step when you double check that after unpacking tar archive your files are with correct timestamps on exteran sd card -> remember to cd to inernal memory location /sdcard/DCIM/Camera before)</span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">$ rm -rf *jpg</span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;"><br /></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: inherit;">-- unpack on external sd card</span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">$ cd /storage/0000-0000/DCIM/Camera</span></span></div>
<span style="font-family: "courier new" , "courier" , monospace;"><span id="docs-internal-guid-75e2b41e-7fff-8494-cf85-437c669a5816"></span></span><br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">herolte:/storage/0000-0000/DCIM/Camera $ tar xvf zzz_jpg.tar</span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;"><br /></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: inherit;">-- check timestamps with </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: "courier new" , "courier" , monospace;">$ ls -al</span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;"><br /></span></div>
<br />Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-64758076614788944472011-02-24T12:29:00.019+01:002011-02-24T17:41:47.288+01:00CSV files in MS Excel and Oracle Open OfficeMy input file is created in MS Excel, it is 1 row of data with 3 columns (in the second column there is a newline character):<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://dl.dropbox.com/u/16264948/YUBLrvYKxexcel_input.png"><img style="margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 331px; height: 131px;" src="http://dl.dropbox.com/u/16264948/YUBLrvYKxexcel_input.png" border="0" alt="" /></a><br /><br />When I save this file as .csv in excel I get following structure:<br /><pre class="code">COL1,COL2,COL3<br />³ó ?????,"2 äöü ??? lines<br />In 1 field ???",+123456<br /></pre><br />File is corrupted<br /><br />When you open this file in Excel no multibytes and even lost "+" in phone number but the new line character properly inserted.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://dl.dropbox.com/u/16264948/dPjQpiLGEexcel_csv_file_corrupted.png"><img style="margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 318px; height: 124px;" src="http://dl.dropbox.com/u/16264948/dPjQpiLGEexcel_csv_file_corrupted.png" border="0" alt="" /></a><br /><br />When I save the input Excel file as Unicode Text .txt the Unicode (MS Unicode ucs-2le) all the issues with .csv will be resolved (while saving).<br /><pre class="code">COL1 COL2 COL3<br /><br />łóś ещьул "2 äöü ыва lines<br />In 1 field ещь" +123456<br /><br /></pre><br />Unfortunately while opening such file with Text Import Wizard:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://dl.dropbox.com/u/16264948/RCwx21XP7wizard1of3.png"><img style="cursor:pointer; cursor:hand;width: 574px; height: 413px;" src="http://dl.dropbox.com/u/16264948/RCwx21XP7wizard1of3.png" border="0" alt="" /></a><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://dl.dropbox.com/u/16264948/CUKsjj1g8wizard2of3.png"><img style="cursor:pointer; cursor:hand;width: 574px; height: 412px;" src="http://dl.dropbox.com/u/16264948/CUKsjj1g8wizard2of3.png" border="0" alt="" /></a><br /><br />In third step you can change type to Text (to rescue phone number):<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://dl.dropbox.com/u/16264948/RCwx21XP7wizard3of3.png"><img style="cursor:pointer; cursor:hand;width: 574px; height: 415px;" src="http://dl.dropbox.com/u/16264948/RCwx21XP7wizard3of3.png" border="0" alt="" /></a><br />After clicking "Finish" the result is dissapointing:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://dl.dropbox.com/u/16264948/cYijKeHTpexcel_txt.png"><img style="cursor:pointer; cursor:hand;width: 293px; height: 121px;" src="http://dl.dropbox.com/u/16264948/cYijKeHTpexcel_txt.png" border="0" alt="" /></a><br />Multibytes and phone number is properly shown, but the newline is broken.<br /><br />When you change the extension of the previous Unicode File from .txt to .csv and double click on it to open it with Excel you will have new line and multibytes but the phone will be corrupted:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://dl.dropbox.com/u/16264948/ch3ukcAMiunicode_as_csv.png"><img style="cursor:pointer; cursor:hand;width: 323px; height: 121px;" src="http://dl.dropbox.com/u/16264948/ch3ukcAMiunicode_as_csv.png" border="0" alt="" /></a><br /><br />When you try to open the same Unicode .csv file with Oracle Open Office:<br />File -> Open -> .csv file<br />In Import Wizard you set character set to Unicode (it's MS Unicode), delimiter to Tab and column types to Text (to rescue phone number):<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://dl.dropbox.com/u/16264948/n0PDMPPJ7ooo_import_UNICODE_csv.png"><img style="cursor:pointer; cursor:hand;width: 798px; height: 598px;" src="http://dl.dropbox.com/u/16264948/n0PDMPPJ7ooo_import_UNICODE_csv.png" border="0" alt="" /></a><br /><br />Success story:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://dl.dropbox.com/u/16264948/n0PDMPPJ7ooo_success.png"><img style="cursor:pointer; cursor:hand;width: 453px; height: 139px;" src="http://dl.dropbox.com/u/16264948/n0PDMPPJ7ooo_success.png" border="0" alt="" /></a><br /><br /><br />The question is:<br />"Why excel cannot properly open a CSV file created by itself?"<br /><br />Or maybe there is a workaround (without modyfing the CSV file) to do so?<br /><br />Oracle Open Office FTW!!!<br /><br/>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-80987324229479242272010-10-22T15:01:00.013+02:002010-10-22T15:42:10.491+02:00validating emails in oracle db using java stored function => and testing from ruby1. email validation function is written in java (flexibility) and compiled as stored procedure in oracle db (performance)<br /><br />1a) write EmailValidations.java:<br /><pre class="code">import java.lang.String;<br />import java.util.regex.Pattern;<br />import java.util.regex.Matcher;<br /><br />class EmailValidations {<br /> public static int is_valid(String email) {<br /> if (email == null || email == "") return 0;<br /><br /> String upper_email = email.toUpperCase();<br /><br /> Pattern p = Pattern.compile("^[\\w\\.-]*[^\\.]@([\\w\\-]+\\.)+[A-Z]{2,4}$");<br /> Matcher m = p.matcher(upper_email);<br /> return m.matches() ? 1: 0;<br /> }<br />}<br /></pre><br /><br />1b) load and compile java class into your oracle db:<br /><pre class="code">$ loadjava -u scott/tiger@emeadb11 -v -resolve EmailValidations.java<br />--> replace scott/tiger@emeadb11 with your valid username/password@tnsname_entry</pre><br /><br />2a). create package that will contain your function<br /><pre class="code">create or replace PACKAGE "MISC_PKG"<br />IS<br />FUNCTION is_email_valid (email_address in varchar) RETURN number;<br />END MISC_PKG;<br />/</pre><br /><br />2b). create package body:<br /><pre class="code">create or replace<br />PACKAGE BODY "MISC_PKG" AS<br /><br />FUNCTION is_email_valid (email_address in varchar) RETURN number<br />AS LANGUAGE JAVA<br />NAME 'EmailValidations.is_valid(java.lang.String) return int';<br /><br />END MISC_PKG;<br />/</pre><br /><br />3) test with ruby-plsql<br /><br />3a) spec_helper.rb that will contain your credentials and include rspecs and ruby-plsql gems<br /><pre class="code">require 'rubygems'<br />require 'rspec'<br />require 'ruby-plsql'<br /><br />DB_USER = "scott"<br />DB_PWD = "tiger"<br />DB_SRVR = "emeadb11"<br /><br />plsql.connection = OCI8.new DB_USER, DB_PWD, DB_SRVR<br />p "connected"<br /><br />plsql.connection.autocommit = false<br /><br />RSpec.configure do |config|<br /> # config.filter_run :focus => true<br /> config.after(:each) do<br /> plsql.rollback<br /> end<br />end<br /></pre><br />3b) write ruby specs spec_is_email_valid.rb<br /><pre class="code">require File.dirname(__FILE__) + '/spec_helper'<br /><br />describe "check is_email_valid function" do<br /> <br /> it "should return 1 for valid emails" do<br /> plsql.misc_pkg.is_email_valid("c123@o2.pl").should == 1 <br /> plsql.misc_pkg.is_email_valid("c@o2.pl").should == 1 <br /> end<br /> <br /> it "should return 0 for invalid emails" do<br /> plsql.misc_pkg.is_email_valid("c123@o2,pl").should == 0 <br /> plsql.misc_pkg.is_email_valid("c@o2pl").should == 0 <br /> end<br /><br /> it "should return 0 as in email_err_reason" do<br /> plsql.misc_pkg.is_email_valid("S.J@GMAIL").should == 0<br /> plsql.misc_pkg.is_email_valid("SY.STORT").should == 0<br /> plsql.misc_pkg.is_email_valid("01516081607").should == 0<br /> end<br /> <br /> <br /> it "should return 0 when invalid characters in it" do<br /> plsql.misc_pkg.is_email_valid("J.AMS.@CATS.ORG").should == 0<br /> plsql.misc_pkg.is_email_valid("STNJ@ISON.CO.ZA/JACO@VTR.CO.ZA").should == 0<br /> end<br /> <br /> it "should return 0 when null email" do<br /> plsql.misc_pkg.is_email_valid("").should == 0<br /> plsql.misc_pkg.is_email_valid(nil).should == 0<br /> end<br />end</pre><br /><br />4) you can test it with:<br /><pre class="code">$ rspec spec_is_email_valid.rb <br />"connected"<br />.....<br /><br />Finished in 5.64 seconds<br />5 examples, 0 failures<br /></pre><br /><br />You can easily extend your tests once the change was done to your is_valid() java function.<br /><br />For more information on testing pl/sql functions from ruby see excelent blog (author of ruby-plsl):<br /><a href="http://blog.rayapps.com/2009/11/27/oracle-plsql-unit-testing-with-ruby/">http://blog.rayapps.com/2009/11/27/oracle-plsql-unit-testing-with-ruby/</a><br /><br/>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com2tag:blogger.com,1999:blog-206224988104064940.post-1569553868700196922010-08-29T23:30:00.006+02:002010-08-29T23:40:59.757+02:001und1.de domain with heroku rails app1. assuming you have an app on heroku appname.heroku.com<br />2. change CNAME entry for DNS on 1und1.de<br /> - Domains<br /> - mark your domainat1und1.de and select DNS -> Einstellungen Bearbeiten<br /> - for CNAME entry put: appname.heroku.com<br /> - apply and wait couple of hours until it’s populated<br />3. in your heroku app you need to add an add-on “Custom Domains” (Basic is free)<br /><pre class="code">$ heroku addons:add custom_domains<br />Adding custom_domains to <appname>... FAILED<br />! Please verify your account before installing this addon<br />! For more information, see http://docs.heroku.com/billing<br />! Verify now at http://heroku.com/verify</pre><br />as you can see you need to verify your account before (credit card needed -> no charge applies)<br /><br />when it’s done:<br /><pre class="code">$ heroku addons:add custom_domains:basic<br />Adding custom_domains:basic to <appname>... done</pre><br /><pre class="code">$ heroku domains:add www.domainat1und1.de<br />Added www.domainat1und1.de as a custom domain name to appname.heroku.com<br />$ heroku domains:add domainat1und1.de<br />Added domainat1und1.de as a custom domain name to appname.heroku.com</pre><br />FULL instructions under: http://docs.heroku.com/custom-domains<br /> <br/>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-9081293726291845722009-10-20T12:59:00.006+02:002009-10-20T13:03:15.252+02:00oracle db - how to identify compilation errors1.<pre class="code">select * from user_errors;</pre><br />2.<pre class="code">SELECT RTRIM(INITCAP(e.type))||' '||e.name||': Line '||<br /> TO_CHAR(e.line)||' Column '||TO_CHAR(e.position) linecol,<br /> s.text sourceline,RPAD(' ',(e.position - 1))||'^' errpos,<br /> e.text error<br />FROM user_source s,user_errors e<br />WHERE e.type = s.type<br />AND e.name = s.name<br />AND e.line = s.line<br />ORDER BY e.name,e.sequence</pre><br />The latter one will give you the exact line where the error occcurs<br/><br/>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-9019845715636781952009-09-23T16:08:00.004+02:002009-09-23T16:21:27.762+02:00encrypting partitions with LUKS in Linuxwith these commands we encrypt a full partition located under /dev/sde1<br />(UUID=7a89446f-c43f-41b1-bc2b-99c74c64cdeb)<br /><br />In the below steps I use dcfldd (which is much more user friendly than dd and gives you progress status) and cryptsetup.<br /><br /><pre class="code">sudo apt-get install dcfldd cryptsetup<br /><br />sudo dcfldd if=/dev/urandom of=/dev/sde1 statusinterval=10 bs=10M conv=notrunc<br />sudo cryptsetup luksFormat /dev/sde1<br />sudo cryptsetup luksOpen /dev/sde1 maxtor_encrypted<br />sudo mkfs.ext3 /dev/mapper/maxtor_encrypted<br />sudo mkdir /mnt/maxtor_enc<br />sudo mount /dev/mapper/maxtor_encrypted /mnt/maxtor_enc -t ext3 -o noatime,nodiratime</pre><br /><br />it is safer to use UUIDs instead of /dev/sde1 because even if order of the drives changes (USB drives, or because of your BIOS) you always can uniquely identify the one with the unique UUID.<br />You can get the UUIDs of all of your disks' partitions by running<br /><pre class="code">$ blkid</pre><br />Now let's write to scripts for mounting and umounting our encrypted drive:<br /><pre class="code">chris@emeadb:~/bin$ cat mycryptmount<br />#!/bin/bash<br />export PATH=/usr/local/bin/:/bin/:/usr/bin/<br />echo "mounting encrypted drive"<br /><br />df | grep maxtor_enc && sudo /home/chris/bin/mycryptumount<br />echo "maxtor_enc umounted"<br /><br />sudo cryptsetup luksOpen /dev/disk/by-uuid/7a89446f-c43f-41b1-bc2b-99c74c64cdeb maxtor_encrypted<br />sudo mount /dev/mapper/maxtor_encrypted /mnt/maxtor_enc -t ext3 -o noatime,nodiratime</pre><br /><pre class="code">chris@emeadb:~/bin$ cat mycryptumount<br />#!/bin/bash<br />export PATH=/usr/local/bin/:/bin/:/usr/bin/<br /><br />sudo umount /dev/mapper/maxtor_encrypted<br />sudo cryptsetup luksClose maxtor_encrypted</pre><br /><br />chmod +x both of them<br /><br />now you are able to mount with<br /><pre class="code">$ mycryptmount</pre><br />and umount with<br /><pre class="code">$ mycrypumount</pre>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-61051086052459767112009-09-13T15:01:00.000+02:002009-09-13T15:02:27.031+02:00Ada - jedne z pierwszych prob efektywnego poruszania sie<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Ga8VTtRg9uU&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Ga8VTtRg9uU&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-43498960187580669382009-05-28T21:06:00.003+02:002009-05-28T21:14:35.006+02:00ruby oracle oci8 UTF8 corruptionI have a small script oci1.rb: <br /><pre class="code">require 'oci8' <br />conn = OCI8.new("test","test","test_db") <br />File.open("out.txt","wb") do |out| <br /> tabs = conn.exec('SELECT * from test_utf8') do |r| <br /> out.write(r.join(',')) <br /> out.write("\n") <br /> end <br />end <br />conn.logoff</pre><br />that runs perfectly on windows producing from my test_db: <br /><pre class="code">polish,łóśżć <br />russsian,фывафыва <br />german,äöü </pre><br />when I run exactly the same on my linux box: <br /><pre class="code">polish,loszc <br />russsian,???????? <br />german,aou </pre><br />I tested then a small script that reads and writes UTF8 on linux to be sure my linux terminal can display UTF8<br />(read_write_utf8.rb): <br /><pre class="code">File.open("utf8_out.txt","wb") do |out| <br /> File.open("utf8.txt","r").each do |line| <br /> out.write(line) <br /> end <br />end </pre><br />and that works good! <br /><pre class="code">chris@emeadb:~/work/ruby/oci$ ruby read_write_utf8.rb <br />chris@emeadb:~/work/ruby/oci$ cat utf8.txt <br />polish,łóśżć <br />russsian,фывафыва <br />german,äöü <br />chris@emeadb:~/work/ruby/oci$ cat utf8_out.txt <br />polish,łóśżć <br />russsian,фывафыва <br />german,äöü </pre><br /><br />Finally the issue was with my NLS_LANG variable that was not set in the Linux box on the account I used for running the script.<br /><br />I tried first to set it up in the ruby script itself:<br /><pre class="code">ENV['NLS_LANG']='AMERICAN_AMERICA.UTF8'</pre><br />that did not work.<br /><br />the solution was to set it in the shell.<br /><pre class="code">export NLS_LANG=AMERICAN_AMERICA.UTF8</pre><br /><br />you can set it in your .bashrc (depending on the shell you use) to make it default for the account.Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-37419718563264736852009-04-22T16:20:00.005+02:002009-04-22T16:45:12.784+02:00debian change from dhcp to static IPOne would think to achieve the update from the DHCP assigned IP to the static one, the only thing to do is to update your /etc/network/interfaces<br /><br />from:<pre class="code">iface eth0 inet dhcp</pre><br />to:<pre class="code">iface eth0 inet static<br /> address 10.165.248.252<br /> netmask 255.255.248.0<br /> gateway 10.165.248.1<br /> broadcast 10.165.248.255<br /> network 10.165.248.0</pre><br />and restart:<pre class="code">/etc/init.d/networking restart</pre><br />(optionally you can adjust your /etc/resolv.conf (to update DNS servers, and search paths)<br /><br />The changed IP is immediately visible.<br /><br />How surprised I was when after couple of hours the IP was changed back to the one from the DHCP pool. (resolv.conf was then automatically updated from the DHCP server)<br /><br />Solution was to kill the dhcp3-client. (and change again the resolv.conf and restart networking)Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-64184944270200665242009-03-30T17:42:00.007+02:002009-03-30T19:02:31.814+02:00ddl over database link in oracle 10gR2recently I encountered a requirement to create a table on remote database DB_TARGET (working in DB_SOURCE)<br /><br />for example:<br /><pre class="code">create table table_a@dblink_to_db_target; --> does not work<br />-- ORA-02021: DDL operations are not allowed on a remote database</pre><br />whereas<br /><pre class="code">select 'hello' from dual@dblink_to_db_target; --> works</pre><br />This is a workaround I used:<br />on TARGET_DB:<br /><pre class="code">CREATE OR REPLACE <br />FUNCTION prepare_table <br /> ( table_name in varchar2) return varchar2 <br /> IS <br /> err_num NUMBER; <br /> err_msg VARCHAR2(100); <br /> sqlstmt varchar2(4000) := ''; <br /> tbl varchar2(30) := ''; <br />BEGIN <br /> if instr(table_name,'.') > 0 then <br /> tbl := substr(table_name,instr(table_name,'.')+1); <br /> sqlstmt := 'CREATE TABLE ' || tbl || ' as select * from ' || <br />table_name; <br /> execute immediate sqlstmt; <br /> return 'table ' || tbl || ' successfully created'; <br /> else <br /> return 'table in owners'' schema'; <br /> end if; <br />EXCEPTION <br /> WHEN others THEN <br /> err_msg := SUBSTR(SQLERRM, 1, 100); <br /> return 'error when creating ' || tbl || '-' || err_msg || '-' <br />|| sqlstmt; <br />END; <br />/ </pre><br />this function creates a table specified as a table_name parameter only <br />if the "." is in the name => goal is to create a table in my_schema <br />from other user's schema. <br />this function works fine when calling this on DB_TARGET: <br /><pre class="code">SQL> set serveroutput on; <br />SQL> declare <br /> 2 result varchar2(300) := ''; <br /> 3 begin <br /> 4 result := prepare_table('other_user.table_a'); <br /> 5 dbms_output.put_line(result); <br /> 6 end; <br /> 7 / <br />table table_a successfully created <br /><br />PL/SQL procedure successfully completed. </pre><br />but then surprisingly to me:<br />when I try to call this function from DB_SOURCE: <br /><pre class="code">SQL> set serveroutput on; <br />SQL> declare <br /> 2 result varchar2(300) := ''; <br /> 3 begin <br /> 4 result := prepare_table@dblink_to_db_target('other_user.table_a'); <br /> 5 dbms_output.put_line(result); <br /> 6 end; <br /> 7 / <br />error when creating gcd_countries-ORA-02064: distributed operation not <br />supported-CREATE TABLE table_a as select * from other_user.table_a <br /><br />PL/SQL procedure successfully completed. </pre><br />I found a workaround with a wrapper procedure on DB_TARGET: <br /><pre class="code">CREATE OR REPLACE <br />PROCEDURE prepare_table_proc(table_name in varchar2) <br /> IS <br /> result varchar2(300) := ''; <br />BEGIN <br /> result := prepare_table(table_name); <br /> dbms_output.put_line('success'); <br />EXCEPTION <br /> WHEN others THEN <br /> dbms_output.put_line('err'); <br />END; <br />/ </pre><br />when I call it from DB_SOURCE like this: <br /><pre class="code">SQL> call prepare_table_proc@dblink_to_db_target('other_user.table_a'); <br />Call completed. </pre><br />And the table_a is created on DB_TARGET. <br /><br />when we look closer why the function itself did not work we see in the description of the error message:<br />ORA-02064: distributed operation not supported <br /> Cause: One of the following unsupported operations was attempted: <br /> 1. array execute of a remote update with a subquery that <br />references a dblink, or <br /> 2. an update of a long column with bind variable and an update of <br />a second column with a subquery that both references a dblink and a <br />bind variable, or <br /> 3. a commit is issued in a coordinated session from an RPC <br />procedure call with OUT parameters or function call. <br /><br />in my case point 3. yields and hence the error message.<br /><br />Oracle documentation comes with help in:<br /><a href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sql.htm#sthref6148">http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sql.htm#sthref6148</a><br /><br />it works only as a procedure and we cannot return a value to the invoking DB_SOURCE anyway.<br /><br />maybe there's a better way...<br />right now I am happy with the workaroundKrzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-29643147624155912542009-02-18T09:14:00.004+01:002009-02-18T09:24:32.169+01:00why you should always use aliases in SQL (oracle)let's create for this example following 2 tables (a and b):<br /><pre class="code">create table a (org_id number, org_name varchar2(1)); <br />insert into a values(1,'a'); <br />insert into a values(2,'b'); <br />insert into a values(3,'c');<br />commit;</pre><br /><pre class="code">create table b (name varchar2(1)); <br />insert into b values('a'); <br />insert into b values('b');<br />commit;</pre><br /><br />Now let's run this:<br /><pre class="code">select * from a <br />where a.org_id in (select org_id from b); <br />-- returns all 3 rows from a <br /><br />select * from a <br />where a.org_id not in (select org_id from b); <br />-- returns 0 rows</pre><br /><br />The tricky part is, you might want the org_id in the subquery to be taken from b (which does not exist) and hence expect an INVALID IDENTIFIER error message as running only subquery:<br /><pre class="code">select org_id from b <br /> * <br />ORA-00904: "ORG_ID": invalid identifier</pre><br /><br />But the initial query is correlated and actually the org_id in the subquery comes from outer table a and not from b.<br /><br />That's why a good practice would be always to use aliases as prefixes to the columns.<br /><br />In that way we can rewrite the query that will now raise an exception as expected:<br /><br /><pre class="code">select * from a <br />where a.org_id not in (select <span style="font-weight:bold;">b.</span>org_id from b); <br />-- ORA-00904: "B"."ORG_ID": invalid identifier</pre>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com1tag:blogger.com,1999:blog-206224988104064940.post-29910959887140391402009-01-22T09:25:00.006+01:002009-01-22T09:38:26.303+01:00vim converting between MS Unicode UCS-2LE and UTF-8Many times at work I need to convert between 2 different encodings from Unicode:<br />1. MS Unicode -> generated e.g. by Excel when Saving data as Unicode text<br />2. UTF8 encoding (standard)<br /><br />Requirement VIM is compiled with multi_byte support.<br />check if in VIM normal mode<br /><pre class="code">:echo has('multi_byte')</pre><br />returns 1<br /><br />In VIM normal mode to open a file with certain encoding:<br /><pre class="code">:e ++enc=<encoding> <filename></pre><br />To save in different encoding:<br /><pre class="code">:w ++enc=<encoding> <filename></pre><br />e.g.<br />open in ucs-2le -> save in utf-8<br /><pre class="code">:e ++enc=ucs-2le /tmp/file_ucs2le.csv<br />:w ++enc=utf-8 /tmp/file_utf8.csv</pre><br />It works even if your fileencoding in your .vimrc (_vimrc on Windows) is different and VIM normally would recognize as different encoding from the one you want.<br /><br />++enc sets fileencoding and not encoding (filencoding is needed when opening or saving the file)<br /><br />More on Unicode in VIM under<br /><a href="http://vim.wikia.com/wiki/Working_with_Unicode">http://vim.wikia.com/wiki/Working_with_Unicode</a>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com4tag:blogger.com,1999:blog-206224988104064940.post-23053815470178478562009-01-20T10:12:00.004+01:002009-01-20T10:19:41.335+01:00compiling VIM 7.2 with GTK2 under debian etchTo install GTK2 is not an issue since we can use the apt-get install libgtk2.0 libgtk2.0-dev to install gtk2 with dev libraries.<br /><br />The issue I encountered was when I tried to compile VIm 7.2 with GTK2, which could not be found:<br /><pre class="code">checking for GTK - version >= 2.2.0... no<br />checking for GTK - version >= 1.1.16... yes; found version 1.2.10</pre><br />Then I decided to compile GTK2 on my own.<br /><br />I failed when trying to install GTK2.14 with GLIB2.18.4 because some function definitions changed.<br /><br />Finally the versions I successfully installed were:<br /><pre class="code">- gtk2.8.20<br />- glib2.9.6<br />- pangoo1.11<br />- atk1.25.2<br />- cairo1.8.6<br />- pixman0.13.2</pre><br />then to compile VIM i used (/opt/gtk2 is the prefix where I installed just compiled gtk2):<br /><pre class="code">export PKG_CONFIG_PATH="/opt/gtk2/lib/pkgconfig"<br />export LD_LIBRARY_PATH=/opt/gtk2/lib<br />export CPPFLAGS="-I/opt/gtk2/include"<br />export LDFLAGS="-L/opt/gtk2/lib"<br /> ./configure --prefix=/opt/vim/ --enable-perlinterp --enable-rubyinterp --enable-multibyte --enable-gui --with-features=big</pre><br />Finally GTK2 found:<br /><pre class="code">checking for GTK - version >= 2.2.0... yes; found version 2.8.20</pre><br />happy VImming :)Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-57550568511673186322008-12-16T11:24:00.005+01:002008-12-16T11:37:11.046+01:00accessing Github from behind HTTP proxyWhen you need to pull or push from <a href="http://github.com">Github </a>(git://) and you're behind corporate HTTP firewall, you might find below instructions helpful:<br /><br />1. set environmental variables (in .bashrc or .bash_profile)<br /><pre class="code">export GIT_SSH="${HOME}/bin/http-ssh"<br />export GIT_PROXY_COMMAND="${HOME}/bin/http-cmd"</pre><br />2. prepare http-ssh and http-cmd in your ${HOME}/bin/ directory (or any other of your choice -> just adjuct the environmental variables accordingly)<br /><pre class="code">#!/bin/sh<br /># Filename: http-ssh<br />ssh -o ProxyCommand="${HOME}/bin/http-cmd %h %p" $@</pre><br /><pre class="code">#!/bin/sh<br /># Filename: http-cmd<br />/usr/bin/connect -H http://<your_http_proxy>:<port> $@</pre><br /><br />now you can freely use git command.Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-66790900687858978702008-12-09T16:39:00.004+01:002008-12-09T16:45:29.977+01:00sftp from behind firewall via HTTP proxy in RubySame as the previous Post using ruby:<br /><pre class="code">require 'rubygems'<br />require 'net/ssh'<br />require 'net/sftp'<br />require 'net/ssh/proxy/http'<br /><br />base_dir = "/some_base_directory"<br /><br />proxy_host = 'IP_or_FQDN_of_your_proxy'<br />proxy_port = port_of_your_proxy<br /><br />proxy = Net::SSH::Proxy::HTTP.new(proxy_host,proxy_port)<br /><br />Net::SSH.start('destination_IP_or_FQDN','username',<br /> {:proxy => proxy,<br /> :password => 'password'}) do |ssh|<br /><br /> ssh.sftp.connect do |sftp|<br /> # do something<br /> end<br />end</pre>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-29061205803882978182008-12-09T16:18:00.006+01:002008-12-09T16:39:27.851+01:00ssh sftp from behind firewall via HTTP proxyIf you work in corporate network that is behind firewall.<br /><br />if you try this:<br /><pre class="code">chris@emeadb:~$ sftp username@xx.xx.xx.xx<br />Connecting to xx.xx.xx.xx...<br />ssh: connect to host xx.xx.xx.xx port 22: No route to host<br />Couldn't read packet: Connection reset by peer</pre><br />With help comes connect-proxy<br />Install it with (in debian like systems):<br /><pre class="code">sudo apt-get install connect-proxy</pre><br />then configure it:<br /><pre class="code">vi ~/.ssh/config</pre><br />adjust to your needs the content:<br /><pre class="code">Host *<br /> ProxyCommand connect-proxy -H <IP or FQDN of your proxy>:<port> %h %p</pre><br />enjoy:<br /><pre class="code">chris@emeadb:~$ sftp username@xx.xx.xx.xx<br />Connecting to xx.xx.xx.xx...<br />Secure SFTP Serverusername@xx.xx.xx.xx's password:</pre>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-55378364776055021772008-11-27T09:29:00.008+01:002008-11-27T09:41:11.105+01:00enabling/disabling ARCHIVELOG in Oracle 10gto check your current mode:<br /><pre class="code">SELECT log_mode FROM v$database;<br /><br />LOG_MODE<br />------------<br />ARCHIVELOG</pre><br />to enable:<br /><pre class="code">SHUTDOWN;<br />STARTUP MOUNT EXCLUSIVE;<br />ALTER DATABASE ARCHIVELOG;<br />ALTER DATABASE OPEN;</pre><br />to disable:<br /><pre class="code">SHUTDOWN;<br />STARTUP MOUNT EXCLUSIVE;<br />ALTER DATABASE NOARCHIVELOG;<br />ALTER DATABASE OPEN;</pre><br />If you receive this error message:<br /><pre class="code">SQL> alter database noarchivelog;<br />alter database noarchivelog<br />*<br />ERROR at line 1:<br />ORA-38774: cannot disable media recovery - flashback database is enabled</pre><br />It means flashback database is set, we need to disable flashback first<br /><pre class="code">SQL> alter database flashback off;<br /><br />Database altered.<br /><br />SQL> alter database noarchivelog;<br /><br />Database altered.<br /><br />SQL> alter database open;<br /><br />Database altered.<br /><br />SQL> SELECT log_mode FROM v$database;<br /><br />LOG_MODE<br />------------<br />NOARCHIVELOG</pre>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-13884643975254739142008-10-30T14:46:00.005+01:002008-11-27T09:25:45.512+01:00oracle archiver hangs because space_used = space_limitHere is how to solve the issue without extending DB_RECOVERY_FILE_DEST_SIZE:<br /><br /><pre class="code">rman target /<br />RMAN> delete archivelog until time 'SYSDATE - 1';<br />or<br />RMAN> delete archive all;<br /><br />RMAN> delete expired archivelog all;<br /></pre>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-80019686307809402232008-09-04T10:59:00.004+02:002008-09-04T11:06:40.453+02:00sql loader and tab separated multibyte fieldswhen you use following part in your control file:<br /><pre class="code">fields terminated by X'0009' optionally enclosed by X'0022'</pre><br />you probably notice that the multi tab characters got swelled to one tab character, which causes that null value fields are gone, and the next non-null fields got shifted in that way, that there are no null values between 2 non-null value fields in db.<br /><br />The solution to this issue is removing the "optionally enclosed ..." statement.Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com1tag:blogger.com,1999:blog-206224988104064940.post-44091511733020870262008-07-24T10:09:00.006+02:002008-07-24T10:21:49.099+02:0010g hangs because of Archiver is unable to archive a redo log because the output devicethe most probable option is that there is no place for your archive logs.<br />If you use flash_recovery_area, increase the size there:<br /><pre class="code">$ sqlplus /nolog<br /><br />SQL> connect sys as sysdba;<br />Enter password: <br />Connected.<br />SQL> select * from v$recovery_file_dest;</pre><br /><br />if <span style="font-weight:bold;">SPACE_USED</span> is the same or close to <span style="font-weight:bold;">SPACE_LIMIT</span> it's definitely this reason (no place to store archive logs)<br /><br />increase the size of flash_recovery area:<br /><br /><pre class="code">SQL> alter system set db_recovery_file_dest_size = 50g scope=BOTH;</pre><br /><br />this will set the size of the flash_recovery_area to 50g immediately, and after restart as well (setting the parameter to SPFILE)<br /><br />If your database is not opened, try to shut it down first.<br /><pre class="code">SQL> shutdown immediate</pre><br />if that takes long time then<br /><pre class="code">SQL> shutdown abort<br />SQL> startup nomount</pre><br /><br />do the stuff written above<br /><pre class="code">SQL> alter database open;</pre>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com1tag:blogger.com,1999:blog-206224988104064940.post-21984307387385771402008-07-16T13:13:00.005+02:002008-07-24T10:09:16.807+02:00sqlplus enabling arrow keys for command historyIt is very annoying when you in sqlplus under Linux cannot use ARROW keys to choose between executed commands.<br />there is a workaround for that, it's name is <span style="font-style: italic;">rlwrap</span>:<br /><pre class="code">sudo apt-get install rlwrap<br /></pre><br />then you can execute:<br /><pre class="code">rlwrap sqlplus /nolog<br /></pre> or create an alias on sqlplus to be executed as <span style="font-style: italic;">rlwrap sqlplus</span>.<br /><br />thanks,<br />chrisKrzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-18767238936697875872008-06-12T17:46:00.004+02:002008-06-12T17:52:57.882+02:00burn big files >4GB under Linux1. prepare a DVD size file:<br /><pre class="code">dd if=/dev/zero of=dvd_file.iso bs=1024 count=4589800<br />mkudffs dvd_file.iso<br />mkdir iso <br />mount -o loop -t udf dvd_file.iso iso<br />cp your_big_file_to_burn iso<br />umount iso</pre><br /><br />2. burn it<br /><pre class="code">cdrecord -verbose -dao -driveropts=burnfree dvd_file.iso</pre>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-27525259337737956172008-06-11T12:46:00.008+02:002009-02-09T10:22:29.699+01:00creating image of NTFS drive under Linux - ntfscloneuse rescucd (www.sysresccd.org with ntfsclone in ver.2.0) for this task.<br /><br />0. mount backup medium on /mnt<br /><br />1. save NTFS image:<br /><pre class="code">ntfsclone --save-image --output /mnt/winxp.img /dev/sda2</pre><br /><br />2. restore NTFS image from image file:<br /><pre class="code">ntfsclone --restore-image --overwrite /dev/sda2 /mnt/winxp.img</pre><br /><br /><span style="font-weight:bold;">UPDATE:</span><br />if your target backup drive is limited to some smaller file size (like 4GB) you might want to compress and split the image into multiple files:<br />e.g. (all one line)<br /><pre class="code">ntfsclone -s -o - /dev/sda2 |gzip|split -b 2000m - /mnt/winxp.img.gz_</pre><br />this will create 2GB big multiple files for that image<br /><br />To restore: (assuming 3 files were created aa, ab, ac)<br /><pre class="code">cat /mnt/winxp.img.gz_aa /mnt/winxp.img.gz_ab /mnt/winxp.img.gz_ac |gunzip -c|ntfsclone --restore-image --overwrite /dev/sda2 -</pre>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-46213741710300518642008-06-11T09:52:00.007+02:002008-06-11T10:43:00.951+02:00partimage to backup restore drive imagesprerequisites:<br />1. partimage (www.partimage.org here 0.6.7)<br />2. rescuecd (www.sysresccd.org here 1.0.3) and burn it on CD<br />3. sfdisk<br />4. 2 drives with same size (or the one that you will be restoring to bigger size) + the backup HDD with some file system on it (in my case ext3 to hold big data files)<br /><br />HowTo Backup:<br />1. attach the backup drive (can be USB HDD, stick, whatever that will save your images - in my case I use 300GB USB drive)<br />2. Boot the rescuecd<br />3. to find out the location of the drive in my case /dev/sdb1, use command<br /><pre class="code">fdisk -l</pre><br /> - if this is linux fs drive with ext3 , use following command:<br /><pre class="code">mount -t ext3 /dev/sdb1 /mnt</pre><br />4. save original MBR with dd<br /><pre class="code">dd if=/dev/sda of=backup-sda.mbr count=1 bs=512</pre><br />5. save all the extended partition entries <br /><pre class="code">sfdisk -d /dev/sda > backup-sda.sf</pre><br /><br />IMPORTANT: save both files from 4. and 5. in safe places (they will be needed to restore the structure of the original to the new disk)<br /><br />6. run partimage command<br /><br />7. mark the partition that you want to back up (e.g. /dev/sda3)<br />8. in the Image file to create/use enter the path to the backup disk<br /> e.g. <pre class="code">/mnt/sda3_partimage</pre><br /><br />9. in Action to be done:<br /> mark - Save partition into a new image file<br />10. press F5 to go to Next Page<br />11. Choose required Compression level (e.g. gz)<br />12. Image split mode if the partitions you save are big, it is wise to split them into the file that fit on CD or DVD (I enter here 4500MB)<br />After continuing with F5 you give a description and the process starts, generating files:<br /> sda3_partimage.000, sda3_partimage.001, etc<br />be careful these file are gzip'ed file, please rename them to sda3_partimage.00X.gz for X in 0,1,2..<br /><br />How To Restore:<br />1. attach the backup drive containing your partimage files and mbr and extended partition entries<br />2. attach empty drive (in my case /dev/sda)<br />3. Boot the rescuecd<br />4. to find out the location of the backup drive in my case /dev/sdb1, use command<br /><pre class="code">fdisk -l</pre><br /> - if this is linux fs drive with ext3 , use following command:<br /><pre class="code">mount -t ext3 /dev/sdb1 /mnt</pre><br />5. restore MBR and extended partition entries:<br /><pre class="code">- dd if=/mnt/backup-sda.mbr of=/dev/sda<br />- sfdisk /dev/sda <> check with fdisk -l if all partitions made on /dev/sda</pre><br />6. make sure backup file names on backup drive (/mnt) are renamed to gz, then gunzip them: <br /><pre class="code">gunzip sda3_patimage.000.gz (will create much bigger sda3_partimage.000 file), <br />... or <br />gunzip sda3_partimage.*.gz </pre><br />7. run partimage command <br />8. Partition to save/resotre (in my case sda3) <br />9. Image file: enter the path to your gunziped image files /mnt/sda3_partimage.000 <br />even if you have more than 1 file, always put the location of the 000 file <br />10. Action to be done: pick Restore partition from an image file After continuing with F5 you should get restored partition on /dev/sda3 <br />11. format SWAP partition (in my case /dev/sda5 -> check your fdisk -l) <br /><pre class="code">mkswap -c /dev/sda5</pre><br />12. Install GRUB boot-loader <br /><pre class="code">mkdir /new_disk<span style="font-family:monospace;"><br /></span>mount /dev/sda3 /new_disk<span style="font-family:monospace;"><br /></span>grub-install --root-directory=/new_disk /dev/sda</pre>Krzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com0tag:blogger.com,1999:blog-206224988104064940.post-14351171454830929902008-04-06T20:19:00.005+02:002008-04-06T20:28:20.809+02:00re-installing GRUBSituation:<br />You have linux and windows on your hdd,<br />As it happened you needed to reinstall M$ Windows, after that operation your GRUB is not visible after reboot.<br /><br />Resolution:<br />1. run any of the Linux LiveCD distros (I used Ubuntu)<br />2. in Console type (as root or sudo):<br /> <pre class="code">-> grub</pre><br />3. in Grub app (I had my linux partition on /dev/sda7 which is mapped to hd0,6 in GRUB):<br /> <pre class="code">-> root (hd0,6)<br />-> setup (hd0,6)</pre><br />4. reboot<br />5. you're done if everything went fine -> I hope so :)<br /><br />thanks,<br />chrisKrzysztof Cierpisz (chris)http://www.blogger.com/profile/07838445516755908113noreply@blogger.com1