aldy120 / self-hosting-wordpress-blog

0 stars 0 forks source link

Backup #9

Open aldy120 opened 1 year ago

aldy120 commented 1 year ago

https://docs.aws.amazon.com/prescriptive-guidance/latest/backup-recovery/backup-recovery-ec2-ebs.html

好的備份是指能夠還原資料的備份。務必經常測試備份是否可成功還原資料。

aldy120 commented 1 year ago
Backup type Description Launch a new instance with preconfigured data Level
AMI Contain Multiple EBS snapshot and configurations Yes Instance
EBS Snapshot One snapshot can restore to one EBS volume No Volume
aldy120 commented 1 year ago

If you are using platform and application AMIs maintained and published by AWS or from the AWS Marketplace, consider maintaining separate volumes for your data. You can back up your data volumes as snapshots that are separate from the operating system and application volumes. Then use the data volume snapshots with newly updated AMIs published by AWS or from the AWS Marketplace. This approach requires careful testing and planning to back up and restore all custom data, including configuration information, on the newly published AMIs.

https://docs.aws.amazon.com/prescriptive-guidance/latest/backup-recovery/ec2-backup.html

aldy120 commented 1 year ago

雖然很想用 EBS snapshot 來做,但好像很麻煩,還要掛載來掛載去的,實在很不熟悉。

我想先用 AMI 的方式試試看。但這樣會缺少 OS 的更新。想說到時候再換成要用新的 Bitnami AMI ,搭配備份相關的 plugin 使用。

目前先使用 AWS Backup 產生每週三的備份。針對所有 tag backup: yes 的資源進行備份。

https://eu-west-1.console.aws.amazon.com/backup/home?region=eu-west-1#/backupplan/details/f0e4367c-34b9-4c1a-83a4-05680bbb2e26

aldy120 commented 1 year ago

也可以考慮使用 WPvivid

但目前我裝起來會失敗,無法產生備份。錯誤訊息是備份的時候會有 ajax 500 error 。

查看這篇 https://docs.bitnami.com/ibm/apps/wordpress/troubleshooting/debug-errors/

懷疑是權限問題,下載 error_log

cd /opt/bitnami/apache2/logs/
scp bitnami@blog-origin.lichi-chen.com:/opt/bitnami/apache2/logs/error_log .

錯誤訊息

[Thu Dec 22 14:54:46.566777 2022] [proxy_fcgi:error] [pid 2040:tid 140547368908544] [client 64.252.133.137:57856] AH01071: Got error 'PHP message: PHP Warning:  opendir(/opt/bitnami/wordpress/wp-content/wpvividbackups/wpvivid_log/): Failed to open directory: No such file or directory in /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid.php on line 5720', referer: https://blog.lichi-chen.com/wp-admin/admin.php?page=WPvivid
[Thu Dec 22 14:54:48.307631 2022] [proxy_fcgi:error] [pid 1702:tid 140547268196096] [client 64.252.133.105:52228] AH01071: Got error 'PHP message: PHP Warning:  fopen(/opt/bitnami/wordpress/wp-content/wpvividbackups/wpvivid_log/wpvivid-63a46fb84a828_backup_log.txt): Failed to open stream: No such file or directory in /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-log.php on line 30PHP message: PHP Fatal error:  Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given in /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-log.php:35\nStack trace:\n#0 /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-log.php(35): fwrite()\n#1 /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-backup.php(241): WPvivid_Log->CreateLogFile()\n#2 /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid.php(1170): WPvivid_Backup_Task->new_backup_task()\n#3 /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid.php(448): WPvivid->pre_backup()\n#4 /opt/bitnami/wordpress/wp-includes/class-wp-hook.php(308): WPvivid->prepare_backup()\n#5 /opt/bitnami/wordpress/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()\n#6 /opt/bitnami/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action()\n#7 /opt/bitnami/wordpress/wp-admin/admin-ajax...', referer: https://blog.lichi-chen.com/wp-admin/admin.php?page=WPvivid
[Thu Dec 22 14:54:48.307976 2022] [proxy_fcgi:error] [pid 1702:tid 140547268196096] [client 64.252.133.105:52228] AH01071: Got error 'PHP message: type: 1, Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given in /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-log.php:35\nStack trace:\n#0 /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-log.php(35): fwrite()\n#1 /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-backup.php(241): WPvivid_Log->CreateLogFile()\n#2 /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid.php(1170): WPvivid_Backup_Task->new_backup_task()\n#3 /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid.php(448): WPvivid->pre_backup()\n#4 /opt/bitnami/wordpress/wp-includes/class-wp-hook.php(308): WPvivid->prepare_backup()\n#5 /opt/bitnami/wordpress/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()\n#6 /opt/bitnami/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action()\n#7 /opt/bitnami/wordpress/wp-admin/admin-ajax.php(188)...PHP message: PHP Warning:  fopen(/opt/bitnami/wordpress/wp-content/wpvividbackups/wpvivid_log/wpvivid-63a46fb84afa3_backup_log.txt): Failed to open stream: No such file or directory in /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-log.php on line 30PHP message: PHP Fatal error:  Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given in /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-log.php:35\nStack trace:\n#0 /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-log.php(35): fwrite()\n#1 /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid.php(509): WPvivid_Log->CreateLogFile()\n#2 [internal function]: WPvivid->deal_prepare_shutdown_error()\n#3 {main}\n  thrown in /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid-log.php on line 35', referer: https://blog.lichi-chen.com/wp-admin/admin.php?page=WPvivid
[Thu Dec 22 14:57:48.905384 2022] [proxy_fcgi:error] [pid 1703:tid 140547091949312] [client 64.252.133.137:53936] AH01071: Got error 'PHP message: PHP Warning:  opendir(/opt/bitnami/wordpress/wp-content/wpvividbackups/wpvivid_log/): Failed to open directory: No such file or directory in /bitnami/wordpress/wp-content/plugins/wpvivid-backuprestore/includes/class-wpvivid.php on line 5720', referer: https://blog.lichi-chen.com/wp-admin/admin.php?page=WPvivid
aldy120 commented 1 year ago

發現首次備份需要權限。使用以下指令暫時給他權限。就可以成功備份了。應該是首次使用的時候要建立某些日誌資料夾時沒權限。

sudo chmod g+w /bitnami/wordpress/wp-content

sudo chmod g-w /bitnami/wordpress/wp-content
ls -ld /bitnami/wordpress/wp-content
aldy120 commented 1 year ago

可以打通 S3 了,本地也可還原 wpvivid 的備份。但 wpvivid 似乎不太理想。他無法把 wp-config 跟 TLS certificate 也一併備份。

aldy120 commented 1 year ago

AWS backup 的 EC2 備份,去 aws backup 點擊 restore 即可。他會建立一台新的機器,裡面完全一模一樣。

只需要把 elastic ip 關聯到新的機器即可。

https://stackoverflow.com/questions/20840012/ssh-remote-host-identification-has-changed

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:hqc5nCiPaMem3yoHbQdrCC24ClbUjtQtNVy95q7EFLw.
Please contact your system administrator.
Add correct host key in /Users/chenlich/.ssh/known_hosts to get rid of this message.
Offending ED25519 key in /Users/chenlich/.ssh/known_hosts:324
Host key for blog-origin.lichi-chen.com has changed and you have requested strict checking.
Host key verification failed.

需要用以下的指令將 known_hosts 洗掉。

ssh-keygen -R blog-origin.lichi-chen.com