суббота, 30 апреля 2011 г.

параллельный ssh

split -b 500m big.tgz big.tgz-part-

for i in `ls *-part-*`; do (sleep 3; scp -P 22 -i /root/.ssh/id_rsa $i root@target:/backup/ &); done
#or
for i in `ls *-part-*`; do (sleep 3; rsync -a --rsh "ssh -p 22 -i /root/.ssh/id_rsa" $i root@target:/backup/ &); done

mysql InnoDB disabled (Unknown)


mysql> SHOW VARIABLES LIKE 'have_innodb';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_innodb | NO |
+---------------+-------+
1 row in set (0.00 sec)



IN /etc/mysql/my.cnf
innodb_buffer_pool_size=1000M # or someone
Restart mysql


mysql> SHOW VARIABLES LIKE 'have_innodb';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_innodb | NO |
+---------------+-------+


mysql stop
Remove /var/lib/mysql/ib_logfile*


mysql start
PROFIT


mysql> SHOW VARIABLES LIKE 'have_innodb';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_innodb | YES |
+---------------+-------+

mysql check

mysqlcheck -Aaco --auto-repair -u root -p

четверг, 21 апреля 2011 г.

Network File Copy using SSH

Network File Copy using SSH
http://ultra.ap.krakow.pl/~bar/DOC/ssh_backup.html
Updated February 20, 2003
Created April 23, 2001
Please note that &&, ||, and -, are documented at the bottom of this page.
PUSH:

    * tar cvf - . | gzip -c -1 | ssh user@host cat ">" remotefile.gz
    * ssh target_address cat " remotefile
    * ssh target_address cat " remotefile
    * cat localfile | ssh target_address cat ">" remotefile
    * cat localfile | ssh target_address cat - ">" remotefile
    * dd if=localfile | ssh target_address dd of=remotefile
    * ssh target_address cat     * ssh target_address cat -     * ( cd SOURCEDIR && tar cf - . ) | ssh target_address "(cd DESTDIR && tar xvpf - )"
    * ( cd SOURCEDIR && tar cvf - . ) | ssh target_address "(cd DESTDIR && cat - > remotefile.tar )"
    * ( cd SOURCEDIR && tar czvf - . ) | ssh target_address "(cd DESTDIR && cat - > remotefile.tgz )"
    * ( cd SOURCEDIR && tar cvf - . | gzip -1 -) | ssh target_address "(cd DESTDIR && cat - > remotefile.tgz )"
    * ssh target_address "( nc -l -p 9210 > remotefile & )" && cat source-file | gzip -1 - | nc target_address 9210
    * cat localfile | gzip -1 - | ssh target_address cat ">" remotefile.gz


PULL:
# ssh target_address cat remotefile > localfile
# ssh target_address dd if=remotefile | dd of=localfile
# ssh target_address cat "<" remotefile >localfile
# ssh target_address cat "<" remotefile.gz | gunzip >localfile

COMPARE:
# ###This one uses CPU cycles on the remote server to compare the files:
# ssh target_address cat remotefile | diff - localfile
# cat localfile | ssh target_address diff - remotefile
# ###This one uses CPU cycles on the local server to compare the files:
# ssh target_address cat

Push: Push local file to remote server.
Pull: Pull remote file from remote server to local machine.

Of course there is always ftp, scp2, nfs, smb and other methods as well.

The above methods make a great Ghost replacement.
One can boot a system using standalone linux on a floppy, such as tomsrtbt and can then proceed to:

   1. backup the local hard drive to a remote server or
   2. download an image from the remote server and place it on the local hard drive.

RSH works just the same as SSH I'm sure, it's jut that ssh or ssh should give you better security.

Note: Compressing and then transferring data is faster than transferring uncompressed data. Use compression before sending data over the wire to achieve faster data transfer speeds.

localfile and remotefile can be files, directories, images, hard drive partitions, or hard drives.
Moving files around on local filesystem:

    * ( cd SOURCEDIR && tar cf - . ) | (cd DESTDIR && tar xvpf - )

FTP VIEW:

    * ftp> get file.gif "| xv -"
    * ftp> get README "| more"

FTP PUSH:

    * ftp> put "| tar cvf - ." myfile.tar
    * ftp> put "| tar cvf - . | gzip " myfile.tar.gz

FTP PULL:

    * ftp> get myfile.tar "| tar xvf -"

Pipes and Redirects:

    * zcat Fig.ps.Z | gv -
    * gunzip -c Fig.ps.gz | gv -
    * tar xvf mydir.tar
    * tar xvf - < mydir.tar
    * cat mydir.tar | tar xvf -
    * tar cvf mydir.tar .
    * tar cvf - . > mydir.tar
    * tar cf - . | (cd ~/newdir; tar xf -)
    * gunzip -c foo.gz > bar
    * cat foo.gz | gunzip > bar
    * zcat foo.gz > bar
    * gzip -c foo > bar.gz
    * cat foo | gzip > bar.gz
    * cat foo | gzip > bar.gz

SSH Keys
see http://www.cpqlinux.com/sshkeys.html
Explanation of &&, ||, and -
&& is shorthand for "if true then do"
|| is shorthand for "if false then do"
These can be used separately or together as needed. The following examples will attempt
to change directory to "/tmp/mydir"; you will get different results based on whether
"/tmp/mydir" exists or not.
cd /tmp/mydir && echo was able to change directory
cd /tmp/mydir || echo was not able to change directory
cd /tmp/mydir && echo was able to change directory || echo was not able to change to directory
cd /tmp/mydir && echo success || echo failure
cd /tmp/mydir && echo success || { echo failure; exit; }

The dash "-" is used to reference either standard input or standard output. The context in which the dash is used is what determines whether it references standard input or standard output.
Homepage: http://www.cpqlinux.com
Site Map: http://www.cpqlinux.com/sitemap-date.html


ext3

single user mode
# init 1
#mount -o ro,remount /dev/sda1
# touch /test
touch: creating `/test': Read-only file system
# mount
/dev/sda1 on / type ext3 (rw)

or
booting to rescue cd
unmounting sda1

Remove the journal feature from the file system (downgrade to ext2)

tune2fs -O ^has_journal /dev/sda1

fsck to delete the journal:

e2fsck -f /dev/sda1

recreate the journal (change back to ext3)

tune2fs -j /dev/sda1

and finally, remount it. On a live system, just reboot it.

Another option would be to change the partition to ext3 in /etc/fstab.

среда, 13 апреля 2011 г.

sed tips&tricks

Удалить теги с файл(ов)

sed -i -e 's#<target>.*</target>##g' file

понедельник, 11 апреля 2011 г.

LVM (LOGICAL VOLUME MANAGER)

1.fdisk /dev/sda ->create 3 partitions + label to 8e
2.partprobe
3.fdisk -l
4.pvcreate /dev/sda8 /dev/sda9
5.pvdisplay /dev/sda8
6.pvdisplay /dev/sda9
7.vgcreate vg0 /dev/sda8 /dev/sda9
8.vgdisplay
9.lvcreate -L +200M -n /dev/vg0/home1
10.lvdisplay /dev/vg0/home1
11.lvcreate -L +300M -n /dev/vg0/var1
12.lvdisplay /dev/vg0/var1
13.mkfs.ext3 /dev/vg0/var1
14 mkfs.ext3 /dev/vg0/home1
15.mkdir /home1
16.mkdir /var1
17.mount /dev/vg0/home1 /home1
18.mount /dev/vg0/var1 /var1
19.cp /etc/a* /home1
20.cp /etc/b* /var1
21.vim /etc/fstab
22.mount -a

TO EXTEND LVM

1.lvdisplay /dev/vg0/home1
2.lvextend -L +200M /dev/vg0/home1
3.ls /home1
4.resize2fs /dev/vg0/home1
5.ls /home1

TO REDUCE LVM

1. lvdisplay
2. umount /var1
3. e2fsck -f /dev/vg0/var1
4. resize2fs /dev/vg0/var1 100M
5. lvreduce -L -100M -n /dev/vg0/var1
6. mount /dev/vg0/var1 /var1
7. df -h

LVM SNAPSHOT

1. lvcreate -L 200M -s -n lv2 /dev/llc/lv1

TO EXTEND PV
1.pvcreate /dev/sda10
2.pvdisplay

TO EXTEND VG
1.vgextend vg0 /dev/sda10
2.vgdisplay vg0

TO REDUCE VG
1.vgreduce vg0 /dev/sda10
2.vgdisplay

TO REDUCE PV
1.pvremove /dev/sda10
2.pvdisplay

REMOVE LVM
1.lvdisplay
2.umount /dev/vg0/home1
3.umount /dev/vg0/var1
4.vim /etc/fstab
5.lvremove /dev/vg0/home1
6.lvremove /dev/vg0/var1
7.lvdisplay

REMOVE VG
1.vgdisplay
2.vgremove /dev/vg0
3.vgdisplay

REMOVE PV
1.pvdisplay
2.pvremove /dev/sda9
3.pvremove /dev/sda8

Источник: http://www.redhatlinux.info/2010/11/lvm-logical-volume-manager.html

Клонирование диска в архив с отображение прогресса:
# dd if=/dev/vgdata/win2008 conv=sync,noerror bs=64k | pv -s 106G -pebrt | gzip -c > /mnt/data/lvm-image/win2008.lvm.raw.gz
21GB 0:03:59 [  10MB/s] [>                                       ]  2% ETA 3:07:21

воскресенье, 10 апреля 2011 г.

Tips&tricks

empty file
root@test:/tmp# dd if=/dev/zero of=templun3 count=0 obs=1 seek=200G
0+0 records in
0+0 records out
0 bytes (0 B) copied, 4.1537e-05 s, 0.0 kB/s
root@test:/tmp# ls -al *lun3*
-rw-r--r-- 1 root root 214748364800 2008-05-03 04:43 templun3

среда, 6 апреля 2011 г.

symfony render PDF 2

require_once("dompdf_config.inc.php");
$html =
    '<html><body>'.
    '<p>Some text</p>'.
    '</body></html>';

$this->$dompdf = new DOMPDF();
$this->$dompdf->load_html($html);
$this->dompdf->set_paper('a4', 'portrait');
$this->dompdf->render();
$pdf = $this->dompdf->output()

$response = $this->getContext()->getResponse();
$response->clearHttpHeaders();
$response->setHttpHeader('Pragma', 'public');
$response->setHttpHeader('Cache-Control', '');
$response->setHttpHeader('Content-Type', 'application/pdf');
// line deleted
$response->setContent($pdf);

return sfView::NONE;

symfony render PDF

public function executePdf(sfWebRequest $request)
  {
    $this->certificate = Doctrine_Core::getTable('Certificate')->findOneByToken(array($request->getParameter('token')));
    $this->forward404Unless($this->certificate);
  //$config = sfTCPDFPluginConfigHandler::loadConfig();
  // pdf object
  $pdf = new myPDF();

  // settings
  $pdf->SetFont("FreeSerif", "", 12);
  /*
  $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
  $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
*/
  //$pdf->setPrintHeader(false);
  $pdf->setPrintFooter(false);
  
  // init pdf doc
  //$pdf->AliasNbPages();
  $pdf->AddPage('L', array(132,66));
  $pdf->Cell(80, 10, "Certificate číslo: ". $this->certificate->token);

  $this->setLayout(false);
  // output
  $response = $this->getContext()->getResponse();
$response->clearHttpHeaders();
$response->setHttpHeader('Pragma', 'public');
$response->setHttpHeader('Cache-Control', '');
$response->setHttpHeader('Content-Type', 'application/pdf');
$response->setHttpHeader('Content-Disposition', 'attachment; filename="invoice.pdf"');
$response->setContent($pdf->Output());

return sfView::NONE;

//  return $pdf->Output();

  // Stop symfony process
 // throw new sfStopException();

  }
}

include '/var/www/oleg/slevy/plugins/sfTCPDFPlugin/lib/tcpdf/tcpdf.php';
// Extend the TCPDF class to create custom Header and Footer
//class MYPDF extends sfTCPDF {
class MYPDF extends TCPDF {


    //Page header
    public function Header() {
        // full background image
        // store current auto-page-break status
        $bMargin = $this->getBreakMargin();
        $auto_page_break = $this->AutoPageBreak;
        $this->SetAutoPageBreak(false, 0);
        $img_file = sfConfig::get('sf_web_dir') . '/images/bg_kupon.jpg';
        $this->Image($img_file, 0, 0, 132, 66, '', '', '', false, 300, '', false, false, 0);
        // restore auto-page-break status
        $this->SetAutoPageBreak($auto_page_break, $bMargin);
    }
}

вторник, 5 апреля 2011 г.

psql tips&tricks

Аналог mysql Group_concat
SELECT array_to_string(array(SELECT DISTINCT a FROM b),', ');


вывод результата в psql во вшешний файл
\o /tmp/text.txt
SELECT array_to_string(array(SELECT DISTINCT a FROM b),', ');

воскресенье, 3 апреля 2011 г.

OpenErp lanchpad

Howto bazar
http://doc.bazaar.canonical.com/latest/en/mini-tutorial/
http://doc.bazaar.canonical.com/latest/en/user-guide/index.html

lanchpad paths:
http://bazaar.launchpad.net/~openerp-community/openobject-addons/trunk-addons-community/files

OpenErp Logger

   import netsvc
   netsvc.Logger().notifyChannel('my_module_or_tag', netsvc.LOG_DEBUG, "Hello")