Docker容器及docker化wordpress的备份与恢复

发布于 2022-11-29  113 次阅读


容器打包

docker commit -p nginx nginx-image

镜像保存

docker save -o nginx-image.tar nginx-image

镜像恢复

docker load -i nginx-image.tar

容器运行

docker run -d -p 80:80 -p 443:443 --name nginx \
-v /data/nginx/www:/usr/share/nginx/html \
-v /data/nginx/logs:/var/log/nginx \
-v /data/nginx/conf:/etc/nginx \
nginx-image

相关原始配置参考:

文件夹备份及恢复

cd /data
tar -zcvf nginx-bak.tar.gz nginx

cd /data
tar -zxvf nginx-bak.tar.gz

docker化wordpress备份

相关原始配置参考:

查看docker volume

docker volume ls

将sql数据保存到/tmp中

docker run --rm -v wordpress_db_data:/var/lib/mysql -v /tmp:/backup alpine tar -cjf /backup/my_wordpress_database_backup.tar.bz2 -C /var/lib/mysql ./

将wordpress数据保存到/tmp中

docker run --rm -v wordpress_wp_site:/var/www/html -v /tmp:/backup alpine tar -cjf /backup/my_wordpress_site_backup.tar.bz2 -C /var/www/html ./

docker化wordpress恢复

先安装相关容器,参考:

再执行恢复

docker run --rm -v wordpress_db_data:/var/lib/mysql -v /tmp:/backup alpine sh -c "rm -rf /var/lib/mysql/* /var/lib/mysql/..?* /var/lib/mysql/.[!.]* ; tar -C /var/lib/mysql/ -xjf /backup/my_wordpress_database_backup.tar.bz2"
docker run --rm -v wordpress_wp_site:/var/www/html -v /tmp:/backup alpine sh -c "rm -rf /var/www/html/* /var/www/html/..?* /var/www/html/.[!.]* ; tar -C /var/www/html/ -xjf /backup/my_wordpress_site_backup.tar.bz2"

Love is merely a madness.