ผู้เขียน หัวข้อ: MySQLDump To a Remote Server  (อ่าน 5901 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ siemens

  • Jr. Member
  • **
  • กระทู้: 87
  • Respect: 0
    • ดูรายละเอียด
MySQLDump To a Remote Server
« เมื่อ: เมษายน 18, 2010, 19:20:44 PM »
0
MySQLDump To a Remote Server
Posted Thu, 2009-04-16 13:15 by Are Casilla
I was running out of disk space on a server today. The server had a large database table that was no longer used, so I wanted to archive it and then drop the table. But the server didn’t have enough disk space to dump it out to disk before copying it off to a remote server for archiving.

The first thought was to run mysqldump dump on the destination machine, and to access the database over the network. That however, doesn’t compress or encrypt the data. Plus I would have had to create a mysql user with permission to access the database remotely.

The solution I came up with worked out well: mysqldump directly to the remote host with this command:

mysqldump [mysqldump options] | gzip -c | ssh user@remotehost "cat > /path/to/some-file.sql.gz"

That pipes the mysqldump command through gzip, then to through and SSH connection. SSH on the remote side runs the ‘cat’ command to read the stdin, then redirects that to the actual file where I want it saved.

By Brandon Checketts
http://www.brandonchecketts.com/archives/mysqldump-to-a-remote-server

// อ่านคร่าวๆ เข้าใจว่าเป็นการแก้ปัญหา disk space ของ server ไม่พอ ด้วยการ dump ข้อมูลไปยัง host ตัวอื่น
   รบกวนอาจารย์ช่วยทานข้อมูลว่าใช่และน่าจะใช้ได้หรือไม่ครับ
อนุโรจน์  วิสุทธิ์เจริญพร

โรงพยาบาลบ้านค่าย อ.บ้านค่าย จ.ระยอง

OS : Hosxp version 3.52.7.3 --->3.53.11.29
Server : CentOS 5.3 + MySQL 5.1.37 percona Ram 10G
Slave   : CentOS 5.3 + MySQL 5.1.37 percona Ram   3G 

since 4 July 2009   by  BMS team

moderator of smart-mobile.com

"What the will wills it has already. For the will wills its will. Its will is what it has willed. The will wills itself." fROM M. Heideggers

ออฟไลน์ กรรมคือการกระทำ

  • Jr. Member
  • **
  • กระทู้: 99
  • Respect: 0
    • ดูรายละเอียด
Re: MySQLDump To a Remote Server
« ตอบกลับ #1 เมื่อ: เมษายน 18, 2010, 19:26:46 PM »
0
ใช้ XtraBackup ข้ามเครื่องจะเร็วกว่านะครับ

คราวนี้เราก็สามารถ กำหนด schedule crond job ให้ส่งข้อมูล Full backup ไปยัง host B อัตโนมัติ ด้วยคำสั่งนี้ครับ  (แทนที่ B ด้วย ip address เครื่องปลายทาง และ 192,0x2e,168,0x2e,1,0x2e,1 คือ IP Address ของเครื่อง Master  ใส่ 0x2e แทนเครื่องหมายจุด เพื่อหลีกเลี่ยงการใช้เครื่องหมาย '  )

หรือจะประยุกต์ใช้สำหรับการนำข้อมูลไปไว้ในเครื่อง Slave ก็ได้ครับ  สามารถลดเวลาที่ใช้ในการ Initial import ลงไปได้ถึง 3 - 20 ชั่วโมงเชียวครับ


ssh root@B 'service mysql stop'

rsync -avP -e ssh /etc/my.cnf root@B:/etc/

rsync -avP -e ssh /usr/bin/xtrabackup root@B:/usr/bin/

rsync -avP -e ssh /usr/bin/innobackupex root@B:/usr/bin/

innobackupex --stream=tar /tmp/--slave-info | ssh root@B "tar xfi - -C /var/lib/mysql/"

echo "Transfer data done wait 5 sec to continue"
sleep 5

ssh root@B 'xtrabackup --prepare --use-memory=150M  --target-dir=/var/lib/mysql'

ssh root@B 'chown mysql:mysql /var/lib/mysql/* -R'

ssh root@B 'service mysql start'

ssh root@B 'mysql -e "show full processlist"'

while [ "$?" -ne "0" ]
do
echo "Wait for slave mysql startup"
sleep 3
ssh root@B 'mysql -e "show full processlist"'
done

ssh root@B 'mysql -e "delete from hos.replicate_cfg"'

ssh root@B 'mysql -e "insert into hos.replicate_cfg (server) values (0)"'

ssh root@B 'mysql -e "update hos.replicate_cfg set server =concat(192,0x2e,168,0x2e,1,0x2e,1)"'

ssh root@B 'mysql -e "update hos.replicate_cfg set lastreplicate = (select max(event_id) from hos.replicate_log)"'

« แก้ไขครั้งสุดท้าย: เมษายน 18, 2010, 19:29:10 PM โดย pompam2 »
Server Master FreeBSD-9.0+MySQL-5.5.30
Server Slave   FreeBSD-8.2+MySQL-5.5.30

doramon

  • บุคคลทั่วไป
Re: MySQLDump To a Remote Server
« ตอบกลับ #2 เมื่อ: เมษายน 20, 2010, 18:11:14 PM »
0
MySQLDump To a Remote Server
Posted Thu, 2009-04-16 13:15 by Are Casilla
I was running out of disk space on a server today. The server had a large database table that was no longer used, so I wanted to archive it and then drop the table. But the server didn’t have enough disk space to dump it out to disk before copying it off to a remote server for archiving.

The first thought was to run mysqldump dump on the destination machine, and to access the database over the network. That however, doesn’t compress or encrypt the data. Plus I would have had to create a mysql user with permission to access the database remotely.

The solution I came up with worked out well: mysqldump directly to the remote host with this command:

mysqldump [mysqldump options] | gzip -c | ssh user@remotehost "cat > /path/to/some-file.sql.gz"

That pipes the mysqldump command through gzip, then to through and SSH connection. SSH on the remote side runs the ‘cat’ command to read the stdin, then redirects that to the actual file where I want it saved.

By Brandon Checketts
http://www.brandonchecketts.com/archives/mysqldump-to-a-remote-server

// อ่านคร่าวๆ เข้าใจว่าเป็นการแก้ปัญหา disk space ของ server ไม่พอ ด้วยการ dump ข้อมูลไปยัง host ตัวอื่น
   รบกวนอาจารย์ช่วยทานข้อมูลว่าใช่และน่าจะใช้ได้หรือไม่ครับ

ทดสอบดูครับพี่

ปัญหาอยู่ที่ว่าเรามันใจได้ขนาดไหน ข้อมูลไปหมดเท่านั้น


ออฟไลน์ มดตานอย ครับ..

  • Hero Member
  • *****
  • กระทู้: 3,137
  • Respect: 0
    • ดูรายละเอียด
Re: MySQLDump To a Remote Server
« ตอบกลับ #3 เมื่อ: เมษายน 20, 2010, 18:15:02 PM »
0
 ??? ??? ??? ???

Nakhonphanom Hospital

MR.Tanoy999 ผู้ใช้งานทั่วไป
tanoy999-at-gmail-dot-com
เริ่ม  1 ตุลาคม 2549  โดย  BMS

ออฟไลน์ siemens

  • Jr. Member
  • **
  • กระทู้: 87
  • Respect: 0
    • ดูรายละเอียด
Re: MySQLDump To a Remote Server
« ตอบกลับ #4 เมื่อ: เมษายน 20, 2010, 18:25:09 PM »
0
MySQLDump To a Remote Server
Posted Thu, 2009-04-16 13:15 by Are Casilla
I was running out of disk space on a server today. The server had a large database table that was no longer used, so I wanted to archive it and then drop the table. But the server didn’t have enough disk space to dump it out to disk before copying it off to a remote server for archiving.

The first thought was to run mysqldump dump on the destination machine, and to access the database over the network. That however, doesn’t compress or encrypt the data. Plus I would have had to create a mysql user with permission to access the database remotely.

The solution I came up with worked out well: mysqldump directly to the remote host with this command:

mysqldump [mysqldump options] | gzip -c | ssh user@remotehost "cat > /path/to/some-file.sql.gz"

That pipes the mysqldump command through gzip, then to through and SSH connection. SSH on the remote side runs the ‘cat’ command to read the stdin, then redirects that to the actual file where I want it saved.

By Brandon Checketts
http://www.brandonchecketts.com/archives/mysqldump-to-a-remote-server

// อ่านคร่าวๆ เข้าใจว่าเป็นการแก้ปัญหา disk space ของ server ไม่พอ ด้วยการ dump ข้อมูลไปยัง host ตัวอื่น
   รบกวนอาจารย์ช่วยทานข้อมูลว่าใช่และน่าจะใช้ได้หรือไม่ครับ

ทดสอบดูครับพี่

ปัญหาอยู่ที่ว่าเรามันใจได้ขนาดไหน ข้อมูลไปหมดเท่านั้น



พี่ติดตรง parameter บางตัวครับ - user@remotehost  ใช่ = sa@192.168.10.xxx ไหม
                                               
                                                - cat > /path/to/some-file.sql.gz =cat > /path/to/hos.sql.gz

                                               - ตรง path ต้องใส่เป็นอย่างอื่นไหม

            แต่อย่าง อ.อ๊อด ว่าคงต้องลองเล่นดู................. ;D
อนุโรจน์  วิสุทธิ์เจริญพร

โรงพยาบาลบ้านค่าย อ.บ้านค่าย จ.ระยอง

OS : Hosxp version 3.52.7.3 --->3.53.11.29
Server : CentOS 5.3 + MySQL 5.1.37 percona Ram 10G
Slave   : CentOS 5.3 + MySQL 5.1.37 percona Ram   3G 

since 4 July 2009   by  BMS team

moderator of smart-mobile.com

"What the will wills it has already. For the will wills its will. Its will is what it has willed. The will wills itself." fROM M. Heideggers