在 Ubuntu 上备份 Apache 配置,通常只需要备份 配置文件目录 和(可选)网站数据、证书、日志。下面按“最常用 → 完整备份”说明。
Apache 配置一般在:
/etc/apache2/
sudo tar -czvf apache2-config-$(date +%F).tar.gz /etc/apache2
生成的文件类似:
apache2-config-2026-01-15.tar.gz
tar -tzvf apache2-config-*.tar.gz
如果你只关心“站点配置”,这些目录最关键:
/etc/apache2/sites-available/
/etc/apache2/sites-enabled/
/etc/apache2/mods-enabled/
/etc/apache2/ports.conf
你也可以单独备份:
sudo tar -czvf apache-sites.tar.gz \
/etc/apache2/sites-available \
/etc/apache2/sites-enabled \
/etc/apache2/ports.conf
/var/www/
/etc/ssl/certs/
/etc/ssl/private/
或 Let’s Encrypt:
/etc/letsencrypt/
sudo tar -czvf apache-full-backup-$(date +%F).tar.gz \
/etc/apache2 \
/var/www \
/etc/letsencrypt
rsync -avz /etc/apache2/ user@backup-server:/backup/ubuntu/apache2/
sudo tar -xzvf apache2-config-2026-01-15.tar.gz -C /
sudo apache2ctl configtest
sudo systemctl restart apache2
sudo apache2ctl configtest
如果你愿意,我可以: