ลดความยุ่งยากในการใช้คลาวด์ พูดคุยกับเจ้าหน้าที่

back up MySQL
Home วิธี backup ฐานข้อมูล MySQL ทั้งหมดผ่าน command-line บน Plesk Linux

วิธี backup ฐานข้อมูล MySQL ทั้งหมดผ่าน command-line บน Plesk Linux

เชื่อมต่อ Server ผ่านทาง SSH

สร้าง directory เพื่อเก็บไฟล์ฐานข้อมูลไว้ที่ root

mkdir /root/mysql_dumps_all
cd /root && /usr/sbin/plesk db -e "show databases" | grep -v -E "^Database|information_schema|performance_schema|phpmyadmin" > dblist.txt
cat /root/dblist.txt | while read i; do /usr/sbin/plesk db dump "$i" > /root/mysql_dumps_all/"$i".sql; done

เมื่อ dump database เรียบร้อยแล้ว สามารถแสดงรายชื่อฐานข้อมูลได้ด้วยคำสั่ง ls -l

ls -l /root/mysql_dumps_all

 

สำหรับวิธีการ restore database ทั้งหมดที่ backup ไว้ข้างต้นนั้น ทำตามนี้ได้เลยครับ

# for i in `cat /root/dblist.txt`; do MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin < /root/mysql_dumps_all/"$i".sql; done

ผู้ให้บริการคลาวด์ไทย
เพื่อธุรกิจของคนไทย

"มุ่งมั่น" และ "มั่นคง"
พร้อมรับมือทุกการเติบโต
Trust Cloud
คลาว์ที่ปลอดภัย
คือรากฐานที่มั่นคง
cloud security
Privacy Overview

When you access a website, it has the ability to store or retrieve data on your browser, primarily in the form of cookies. This data could pertain to your preferences, device, or personal information, and is primarily used to optimize the website functionality according to your expectations. While this information typically does not enable direct identification, it does provide a more tailored online experience. As we value your privacy, you are able to selectively decline certain cookie types. Please click on the various category headings to gain more insights and modify our default settings. However, note that preventing certain cookies may impact the level of service and site functionality that we can offer you, please read the full privacy policy