BMS-HOSxP Community

HOSxP => MySQL => ข้อความที่เริ่มโดย: siemens ที่ เมษายน 18, 2010, 19:20:44 PM

หัวข้อ: MySQLDump To a Remote Server
เริ่มหัวข้อโดย: siemens ที่ เมษายน 18, 2010, 19:20:44 PM
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 ตัวอื่น
   รบกวนอาจารย์ช่วยทานข้อมูลว่าใช่และน่าจะใช้ได้หรือไม่ครับ
หัวข้อ: Re: MySQLDump To a Remote Server
เริ่มหัวข้อโดย: กรรมคือการกระทำ ที่ เมษายน 18, 2010, 19:26:46 PM
ใช้ 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)"'

หัวข้อ: Re: MySQLDump To a Remote Server
เริ่มหัวข้อโดย: doramon ที่ เมษายน 20, 2010, 18:11:14 PM
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 ตัวอื่น
   รบกวนอาจารย์ช่วยทานข้อมูลว่าใช่และน่าจะใช้ได้หรือไม่ครับ

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

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

หัวข้อ: Re: MySQLDump To a Remote Server
เริ่มหัวข้อโดย: มดตานอย ครับ.. ที่ เมษายน 20, 2010, 18:15:02 PM
 ??? ??? ??? ???
หัวข้อ: Re: MySQLDump To a Remote Server
เริ่มหัวข้อโดย: siemens ที่ เมษายน 20, 2010, 18:25:09 PM
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