Jump to content
View in the app

A better way to browse. Learn more.

PHP论坛人

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

每日自動備份、僅保留最近3天備份檔、異地備份

Featured Replies

backup.sh 腳本在此下載

backup.sh

-----------------------------------

每日自動備份腳本 backup.sh

-----------------------------------

前面的步驟,已說明可使用 backup.sh 腳本完成 每日自動備份、僅保留最近3天的備份檔

定時備份:每天早上3點執行備份 (或者再SSH登入並敲 crontab -e 修改每日備份的時間點)

備份內容:正常會產生兩種類型的備份檔:DB資料庫備份檔、Web網站檔案備份檔

存放位置:備份檔 預設存放目錄:/var/www/backup/

----------------------------------

自動清理舊備份,僅保留最近3天

----------------------------------

backup.sh 腳本中已內建「自動清理舊備份」的機制,預設設定為:

僅保留最近3天的備份檔

超過3天的檔案會自動刪除

此圖片是只保留2天備份檔的例子

backup.png

如何調整保留天數?

在腳本中搜尋關鍵字 3day,將數字 3 修改為你想要的天數,例如改為 7 即可保留7天的備份

----------------------------

手動異地備份 (人工方式)

----------------------------

若你希望自行將備份檔儲存到其他位置 (例如:另一台主機),可使用以下方式:

使用 scp、rsync 將備份檔傳送至其他主機

手動上傳備份檔至雲端空間 (例如:Google Drive、OneDrive、NAS)

-----------------------

自動異地備份 (進階)

-----------------------

若希望備份流程完全自動化,建議將「異地備份」也納入排程中

常見作法包括:

使用 rclone 同步至 Google Drive、OneDrive、AWS S3

在 backup.sh 執行完成後,呼叫同步腳本。

或建立獨立同步腳本,並在 crontab 中設定於備份完成後30分鐘執行

--------------

建議與提醒

--------------

請定期檢查備份檔是否正常產生

建議至少測試一次「還原流程」,確保備份可用

若使用雲端同步,請注意帳號權限與儲存空間是否足夠

異地備份的存取權限請妥善控管,避免資料外洩

Edited by Jack

Create an account or sign in to comment

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.