怎樣備份部署在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.