在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 环境。