在CentOS系統中部署LNMP(Linux, Nginx, MySQL/MariaDB, PHP)環境時,備份和恢復策略是非常重要的。以下是一個詳細的備份和恢復策略:
使用mysqldump
命令備份MySQL數據庫。例如,備份名為wordpress
的數據庫:
mysqldump wordpress > wordpress.bak
將備份文件傳輸到安全的位置,可以使用scp
命令:
scp wordpress.bak user@remote_host:/path/to/backup/directory
使用rsync
或cp
命令備份網站文件和配置文件。例如,將/var/www/html
目錄備份到遠程服務器:
rsync -av /var/www/html/ user@remote_host:/path/to/backup/directory
或者使用cp
命令保留權限復制:
cp -rp /var/www/html/* user@remote_host:/path/to/backup/directory
/etc/nginx/nginx.conf
和/etc/my.cnf
。將備份文件傳輸回新的服務器。
使用mysql
命令恢復數據庫:
mysql -u root -p wordpress < wordpress.bak
使用rsync
或cp
命令將備份文件復制回新的服務器。
例如,將備份文件復制回/var/www/html
目錄:
rsync -av user@remote_host:/path/to/backup/directory/ /var/www/html/
或者使用cp
命令:
cp -rp user@remote_host:/path/to/backup/directory/* /var/www/html/
停止Nginx和MySQL服務:
systemctl stop nginx
systemctl stop mariadb
備份當前的配置文件:
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
cp /etc/my.cnf /etc/my.cnf.backup
將新的配置文件復制回服務器:
cp /path/to/new/nginx.conf /etc/nginx/nginx.conf
cp /path/to/new/my.cnf /etc/my.cnf
啟動Nginx和MySQL服務:
systemctl start nginx
systemctl start mariadb
檢查Nginx和MySQL服務是否正常運行:
systemctl status nginx
systemctl status mariadb
訪問網站,確認數據是否完整。
chown
和chmod
修復。以上就是CentOS LNMP環境的備份和恢復策略,希望對您有所幫助。