怎样备份部署在EC2上的WordPress站点

手动备份

备份网页部分(html, php),这部分不需要经常备份,如果没修改code或者更新plug,主题之类的

zip -r wp-backup-<date>.zip <wordpress site path>

备份MySQL,这部分需要更频繁,所有的内容都在database里

sudo mysqldump -u <db user> -p –databases <db1> [db2, db3…] > <db backup filename>.sql

然后可以sftp复制到本地或者上传到s3之类的cloud storage里。

备份Script

编辑 backup_db.sh 文件如下

ssh -i <pem file path> <user>@<ip> 'mysqldump -u root -p --databases <db1> [db2, db3, ...] > <server backup path>/<db_backup_file>.sql';
scp -i <pem file path> <user>@<ip>:<server backup path>/<db_backup_file>.sql <local backup path>;
ssh -i <pem file path> <user>@<ip> '<server backup path>/<db_backup_file>.sql'

编辑 backup_html.sh 文件如下

ssh -i <pem file path> <user>@<ip>  'zip -r <site backup path and file name>.zip <site path>';
scp -i <pem file path> -r <user>@<ip>:<site backup path and file name>.zip <local back up path>;
ssh -i <pem file path> <user>@<ip> 'rm <site backup path and file name>.zip'

以后需要backup的时候运行这两文件即可

./backup_db.sh
./backup_html.sh

Leave a Comment

Your email address will not be published.