Linux網(wǎng)絡(luò)備份MySQL的方法_MySQL
Jun 01, 2016 pm 02:02 PM??? 筆者是一個(gè)中小Linux網(wǎng)站的管理員,系統(tǒng)構(gòu)架是:RHEL 4.0 + PHP 4.3 + Mysql 4.03 +Apache 1.23。日均IP訪問(wèn)量在200次,一個(gè)典型的Linux小型網(wǎng)站。由于是小型網(wǎng)站,所以沒(méi)有經(jīng)費(fèi)使用磁帶機(jī)進(jìn)行系統(tǒng)備份,使用的DVD光盤刻錄機(jī)+網(wǎng)絡(luò)硬盤。隨著Linux的應(yīng)用日益廣泛,特別是在網(wǎng)絡(luò)應(yīng)用方面,有大量的網(wǎng)絡(luò)服務(wù)器使用Linux操作系統(tǒng)。由于Linux的桌面應(yīng)用和Windows相比還有一定的差距,所以在企業(yè)應(yīng)用中往往是Linux和Windows操作系統(tǒng)共存形成異構(gòu)網(wǎng)絡(luò)。在服務(wù)器端大多使用Linux和Unix的,PC端使用Windows 9X/2000/XP。
??? 一、本地備份
??? 使用 mysqldump進(jìn)行備份非常簡(jiǎn)單,如果要備份數(shù)據(jù)庫(kù)“ phpbb_db_backup ”,使用命令:#mysqldump –u -p phpbb_db_backup > /usr/backups/mysql/ phpbb_db_backup.2005.5.6
??? 還可以使用gzip命令對(duì)備份文件進(jìn)行壓縮:
??? #mysqldump phpbb_db_backup | gzip > /usr/backups/mysql/ phpbb_db_backup.2005.5.6。gz
??? 恢復(fù)數(shù)據(jù)使用命令:
??? #mysql–u -p phpbb_db_backup
??? 二、備份數(shù)據(jù)到DVD盤片
??? 隨著MYSQL數(shù)據(jù)量的增大,使用傳統(tǒng)CD—R來(lái)備份硬盤并不現(xiàn)實(shí),采用CD—RW分卷制作實(shí)在太麻煩、磁帶機(jī)對(duì)于中小企業(yè)又過(guò)于昂貴。另外各個(gè)應(yīng)用程序的復(fù)雜度日與劇增, 處理的數(shù)據(jù)量也都相當(dāng)龐大,Linux用戶常常遇到的問(wèn)題就是 : 有什么辦法可以經(jīng)濟(jì)快捷的對(duì)數(shù)據(jù)做備份與保存。隨著DVD刻錄機(jī)和盤片的價(jià)格迅速降低,使用DVD刻錄機(jī)用來(lái)備份Linux操作系統(tǒng)非常明智的。
??? 1、安裝
??? 下面以IDE接口的內(nèi)置刻錄設(shè)備為例,介紹在Linux環(huán)境中使用DVD刻錄機(jī)。Linux 需要將IDE接口的刻錄設(shè)備虛擬為SCSI設(shè)備才能進(jìn)行DVD刻錄。2.4以上內(nèi)核Linux發(fā)行版本包含了已編譯進(jìn)內(nèi)核的 SCSI 仿真,所以只要對(duì)啟動(dòng)文件作一些小改動(dòng);USB或1394(FireWire)接口的外置刻錄機(jī)就簡(jiǎn)單多了。
??? 把DVD刻錄機(jī)設(shè)備接入計(jì)算機(jī)第二個(gè)IDE接口(dev/hdc),開(kāi)啟電源。假設(shè)系統(tǒng)用Grub啟動(dòng),用文本編輯器打開(kāi)/boot/grub/grub.conf,找到以“kernel”開(kāi)頭的一行,在這行內(nèi)容的未尾加入“hdc=ide-scsi”,例如:“kernel /vmlinuz-2.4.20-8? ro root=LABEL=/ hdc=ide-scsi”。
??? 2、安裝刻錄軟件
??? DVD+RW-Tools :一個(gè)包含有用于刻錄DVD和映像的軟件工具包,包括:Growisofs和dvd+rw-format。官方站點(diǎn):linux/DVD+RW/">http://fy.chalmers.se/~appro/linux/DVD+RW/ ,? CDRDAO :DAO即是Disk-At-Once(實(shí)時(shí)刻錄),是一種在燒錄過(guò)程中沒(méi)有音軌間的兩秒緩沖的刻錄方法。它可以對(duì)磁盤的布局和磁道進(jìn)行完全的控制,這一功能在刻錄多來(lái)源的盤片相當(dāng)有幫助。
??? cdrtools:包含了一套用于CD、DVD刻錄的工具。Growisofs在創(chuàng)建映像時(shí)會(huì)使用這個(gè)軟件包中的mkisofs工具,并且用戶可以使用readcd來(lái)從一個(gè)現(xiàn)有的DVD上創(chuàng)建ISO映像。此外,Cdrecord應(yīng)用程序可被用于掃描連接系統(tǒng)上的CD/DVD刻錄機(jī),并且可以使用它來(lái)將ISO映像刻錄到CD—R(W)光盤上。通常大多數(shù)Linux版本包括這個(gè)軟件,也可以下載使用:http://freshmeat.net/redir/cdrecord/35795/url_homepage/cdrecord.html dvdrecord:命令行下的DVD刻錄軟件。命令行下的DVD刻錄可用于很多種情形,比如當(dāng)我們通過(guò)遠(yuǎn)程訪問(wèn)主機(jī)時(shí),機(jī)器上的圖形界面無(wú)法啟動(dòng)時(shí),或者機(jī)器由于某些原因無(wú)法啟動(dòng)GUI時(shí)。此外,在完成一些備份等自動(dòng)重復(fù)的功能時(shí),也需要使用命令行工具。
??? 以上介紹了一下必須的軟件和相關(guān)下載網(wǎng)址,安裝過(guò)程比較簡(jiǎn)單,這里就不贅述了。
??? 3、命令行下刻錄
??? 使用DVD+RW-Tools進(jìn)行刻錄工作
??? growisofs是DVD+RW-Tools一個(gè)工具,Growlsofs訪問(wèn)其刻錄設(shè)備使用的是一種不同的方式。它使用/dev下面的Unix路徑來(lái)連接刻錄機(jī)。不同的系統(tǒng)和發(fā)行版中用于刻錄機(jī)的路徑不盡相同,所以最好的方法是查看發(fā)行版中的幫助。在一些系統(tǒng)中,一個(gè)名為/dev/dvd的軟鏈接會(huì)被設(shè)置成指向可用的DVD刻錄機(jī),在本文中,使用/dev/dvd來(lái)指定刻錄機(jī),如果系統(tǒng)中路徑設(shè)置不同,那么請(qǐng)使用合適的路徑將其取代。
??? (1)格式化可讀寫DVD光盤
??? 可以使用DVD+RW-Tools工具包中提供的dvd十rw—format命令。它有兩種格式化DVD光盤的方式:快速模式、完全模式??焖倌J剑?/p>
??? #dvd+rw-format -blank /dev/dvd
??? 完全模式:
??? #dvd+rw-format -blank=full /dev/dvd
??? (2)將文件存儲(chǔ)至DVD刻錄盤:
??? DVD和普通的光盤一樣,使用的也是ISO9660文件系統(tǒng),以及同樣的通用擴(kuò)展(Joliet和RockRidge)。Growlsofs提供了一種簡(jiǎn)單的將文件或目錄存儲(chǔ)至DVD刻錄盤的方法。先用調(diào)用mkisofs工具來(lái)創(chuàng)建一個(gè)映像,并且無(wú)需在將該映像存儲(chǔ)至硬盤之前就刻錄下來(lái)。其基本的命令格式如下:
??? #growisofs -dvd-compat -Z /dev/dvd -J -R /path/to/home/cao
??? 此命令將/path/to/home/cao目錄下的文件制作一個(gè)映像并且刻錄到的DVD光盤。
??? 三、網(wǎng)絡(luò)備份
??? 將MYSQL數(shù)據(jù)放在一臺(tái)計(jì)算機(jī)上是不安全的,所以應(yīng)當(dāng)把數(shù)據(jù)備份到局域網(wǎng)中其他計(jì)算機(jī)中。假設(shè)Mysql服務(wù)器IP地址是:192.168.1.3。局域網(wǎng)使用Linux的遠(yuǎn)程計(jì)算機(jī)IP地址是192.168.1.17;局域網(wǎng)使用Windows的遠(yuǎn)程計(jì)算機(jī)IP地址是192.168.1.18。網(wǎng)絡(luò)拓?fù)湟?jiàn)圖1.
??? 1. 通過(guò)NFS網(wǎng)絡(luò)備份類似于windows的網(wǎng)絡(luò)共享,UNIX(Linux)系統(tǒng)也有自己的網(wǎng)絡(luò)共享,那就是NFS(網(wǎng)絡(luò)文件系統(tǒng)),在linux客戶端掛接(mount)NFS磁盤共享之前,必須先配置好NFS服務(wù)端。linux系統(tǒng)NFS服務(wù)端配置方法如下:(1)修改 /etc/exports,增加共享目錄/export/home/sunky 192.168.1.17(rw)
??? /export/home/sunky1 *(rw)
??? /export/home/sunky2 linux-client(rw)
??? 注:/export/home/目錄下的sunky、sunky1、sunky2是準(zhǔn)備共享的目錄,10.140.133.23、*、linux-client是被允許掛接此共享linux客戶機(jī)的IP地址或主機(jī)名。如果要使用主機(jī)名linux-client必須在服務(wù)端主機(jī)/etc/hosts文件里增加linux-client主機(jī)ip定義。格式如下:192.168.1.17 linux-client若修改/etc/export文件增加新的共享,應(yīng)先停止NFS服務(wù),再啟動(dòng)NFS服務(wù)方能使新增加的共享起作用。使用命令exportfs -rv也可以達(dá)到同樣的效果。linux客戶端掛接(mount)其他linux系統(tǒng)或UNIX系統(tǒng)的NFS共享。這里我們假設(shè)192.168.1.17是NFS服務(wù)端的主機(jī)IP地址,當(dāng)然這里也可以使用主機(jī)名,但必須在本機(jī)/etc/hosts文件里增加服務(wù)端ip定義。/export/home/sunky為服務(wù)端共享的目錄。如此就可以在linux客戶端通過(guò)/mnt/nfs來(lái)訪問(wèn)其它linux系統(tǒng)或UNIX系統(tǒng)以NFS方式共享出來(lái)的文件了。
??? 把MYSQL數(shù)據(jù)備份到使用Linux的遠(yuǎn)程計(jì)算機(jī)需要在兩端都安裝NFS協(xié)議(Network File System),遠(yuǎn)程N(yùn)FS計(jì)算機(jī)安裝NFS協(xié)議后還要修改配置文件:/etc/exports,加入一行:/usr/backups/mysql/ 192.168.1.17 (rw, no_root_squash)表示將/usr/backups/mysql/目錄共享。這個(gè)目錄具有遠(yuǎn)程root用戶讀寫權(quán)限。保存NFS配置文件,然后使用命令:
??? #exportfs -a–r
??? 然后重新啟動(dòng)NFS服務(wù):
??? #service nfsd start
??? 遠(yuǎn)程計(jì)算機(jī)設(shè)定后,在MYSQL服務(wù)器/mnt 目錄下建立一個(gè)backup_share目錄:
??? #mkdir /mnt/backup_share
??? 將遠(yuǎn)程的Linux計(jì)算機(jī)的/usr/backups/mysql/目錄掛載到MYSQL服務(wù)器的/mnt/backup_share目錄下:
??? # mount -t nfs 192.168.1.17:/usr/backups/mysql /mnt/backup_share將目錄掛載進(jìn)來(lái)后,只要進(jìn)入/mnt/backup_share 目錄,就等于到了IP地址:192.168.1.7那部NFS 計(jì)算機(jī)的/usr/backups/mysql??? 目錄中。下面使用mysqldump把“phpbb_db_backup”備份到遠(yuǎn)程計(jì)算機(jī):# mysqldump phpbb_db_backup > /mnt/backup_share/ phpbb_db_backup.2009-5-6 2. 通過(guò)Samba網(wǎng)絡(luò)備份Windows網(wǎng)絡(luò)共享的核心是SMB/CIFS,在linux下要掛接(mount)windows的磁盤共享,就必須安裝和使用samba軟件包?,F(xiàn)在流行的linux發(fā)行版絕大多數(shù)已經(jīng)包含了samba軟件包,如果安裝linux系統(tǒng)時(shí)未安裝samba請(qǐng)首先安裝samba。當(dāng)然也可以到www.samba.org網(wǎng)站下載samba軟件包,現(xiàn)在最新的版本是3.0.10版。然后Windows計(jì)算機(jī)上建立一個(gè)目錄(/arc)并且共享,賦予其讀寫權(quán)限。同樣在MYSQL服務(wù)器/mnt 目錄下建立一個(gè)backup_share1目錄,然后進(jìn)行掛載:# mount -t smbfs -o username=cjh, password=XXXX //192.168.1.18/arc /mnt/backup_share
??? 最后使用命令進(jìn)行備份:
??? # mysqldump phpbb_db_backup > /mnt/backup_share/ phpbb_db_backup.2009-5-6

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are three main ways to set environment variables in PHP: 1. Global configuration through php.ini; 2. Passed through a web server (such as SetEnv of Apache or fastcgi_param of Nginx); 3. Use putenv() function in PHP scripts. Among them, php.ini is suitable for global and infrequently changing configurations, web server configuration is suitable for scenarios that need to be isolated, and putenv() is suitable for temporary variables. Persistence policies include configuration files (such as php.ini or web server configuration), .env files are loaded with dotenv library, and dynamic injection of variables in CI/CD processes. Security management sensitive information should be avoided hard-coded, and it is recommended to use.en

PHP plays the role of connector and brain center in intelligent customer service, responsible for connecting front-end input, database storage and external AI services; 2. When implementing it, it is necessary to build a multi-layer architecture: the front-end receives user messages, the PHP back-end preprocesses and routes requests, first matches the local knowledge base, and misses, call external AI services such as OpenAI or Dialogflow to obtain intelligent reply; 3. Session management is written to MySQL and other databases by PHP to ensure context continuity; 4. Integrated AI services need to use Guzzle to send HTTP requests, safely store APIKeys, and do a good job of error handling and response analysis; 5. Database design must include sessions, messages, knowledge bases, and user tables, reasonably build indexes, ensure security and performance, and support robot memory

When choosing a suitable PHP framework, you need to consider comprehensively according to project needs: Laravel is suitable for rapid development and provides EloquentORM and Blade template engines, which are convenient for database operation and dynamic form rendering; Symfony is more flexible and suitable for complex systems; CodeIgniter is lightweight and suitable for simple applications with high performance requirements. 2. To ensure the accuracy of AI models, we need to start with high-quality data training, reasonable selection of evaluation indicators (such as accuracy, recall, F1 value), regular performance evaluation and model tuning, and ensure code quality through unit testing and integration testing, while continuously monitoring the input data to prevent data drift. 3. Many measures are required to protect user privacy: encrypt and store sensitive data (such as AES

To enable PHP containers to support automatic construction, the core lies in configuring the continuous integration (CI) process. 1. Use Dockerfile to define the PHP environment, including basic image, extension installation, dependency management and permission settings; 2. Configure CI/CD tools such as GitLabCI, and define the build, test and deployment stages through the .gitlab-ci.yml file to achieve automatic construction, testing and deployment; 3. Integrate test frameworks such as PHPUnit to ensure that tests are automatically run after code changes; 4. Use automated deployment strategies such as Kubernetes to define deployment configuration through the deployment.yaml file; 5. Optimize Dockerfile and adopt multi-stage construction

The core idea of PHP combining AI for video content analysis is to let PHP serve as the backend "glue", first upload video to cloud storage, and then call AI services (such as Google CloudVideoAI, etc.) for asynchronous analysis; 2. PHP parses the JSON results, extract people, objects, scenes, voice and other information to generate intelligent tags and store them in the database; 3. The advantage is to use PHP's mature web ecosystem to quickly integrate AI capabilities, which is suitable for projects with existing PHP systems to efficiently implement; 4. Common challenges include large file processing (directly transmitted to cloud storage with pre-signed URLs), asynchronous tasks (introducing message queues), cost control (on-demand analysis, budget monitoring) and result optimization (label standardization); 5. Smart tags significantly improve visual

Building an independent PHP task container environment can be implemented through Docker. The specific steps are as follows: 1. Install Docker and DockerCompose as the basis; 2. Create an independent directory to store Dockerfile and crontab files; 3. Write Dockerfile to define the PHPCLI environment and install cron and necessary extensions; 4. Write a crontab file to define timing tasks; 5. Write a docker-compose.yml mount script directory and configure environment variables; 6. Start the container and verify the log. Compared with performing timing tasks in web containers, independent containers have the advantages of resource isolation, pure environment, strong stability, and easy expansion. To ensure logging and error capture

Select logging method: In the early stage, you can use the built-in error_log() for PHP. After the project is expanded, be sure to switch to mature libraries such as Monolog, support multiple handlers and log levels, and ensure that the log contains timestamps, levels, file line numbers and error details; 2. Design storage structure: A small amount of logs can be stored in files, and if there is a large number of logs, select a database if there is a large number of analysis. Use MySQL/PostgreSQL to structured data. Elasticsearch Kibana is recommended for semi-structured/unstructured. At the same time, it is formulated for backup and regular cleaning strategies; 3. Development and analysis interface: It should have search, filtering, aggregation, and visualization functions. It can be directly integrated into Kibana, or use the PHP framework chart library to develop self-development, focusing on the simplicity and ease of interface.

To solve the problem of inconsistency between PHP environment and production, the core is to use Kubernetes' containerization and orchestration capabilities to achieve environmental consistency. The specific steps are as follows: 1. Build a unified Docker image, including all PHP versions, extensions, dependencies and web server configurations to ensure that the same image is used in development and production; 2. Use Kubernetes' ConfigMap and Secret to manage non-sensitive and sensitive configurations, and achieve flexible switching of different environment configurations through volume mounts or environment variable injection; 3. Ensure application behavior consistency through unified Kubernetes deployment definition files (such as Deployment and Service) and include in version control; 4.
