---
# System prepended metadata

title: 樹梅派筆記-自動備份系統
tags: [Linux, 'null', 樹莓派]

---

---
title: 
description: 
date: 2023-04-16
lang: zh-tw
tags:
  - 樹莓派
  - Linux
  - 
---
# 樹梅派筆記-自動備份系統

以防系統被玩壞，且常用的Timeshift不適合在這類arm小機器上運行。

## 前置需求

需要事先分割好硬碟並掛載好

## 安裝
使用安裝腳本
```zsh=
curl -s https://raw.githubusercontent.com/framps/raspiBackup/master/installation/install.sh | sudo bash
```
安裝完後會進入類似`raspi-config`的選單

## 基礎設定
Backup path: `/backup`(先前已經設定好)
Backup versions: `Smart backup strategy`
Backup type: `Backup with rsync and use hardlinks if possible` 
Backup mode: `Backup the two standard partitions`
Message verbosity: `Display all messages`
Regular backup: `Enable regular backup`-`Weekday of regular backup`-`Daily`

目前用不到`Services to stop and start`暫時預設就好
等以後有檔案傳輸類型的服務，需特別設定

## 擴展設定
安裝官方擴展
```zsh=
raspiBackupInstallUI.sh -e
```
安裝社群擴展`raspiBackup_docker`
```zsh=
sudo wget -P /usr/local/bin https://raw.githubusercontent.com/framps/raspiBackup/master/extensions_userprovided/raspiBackup_docker_post.sh
sudo wget -P /usr/local/bin https://raw.githubusercontent.com/framps/raspiBackup/master/extensions_userprovided/raspiBackup_docker_pre.sh
```
* `-P` - 指定下載到本機的某個目錄下

添加執行權限
```zsh=
sudo chmod 755 /usr/local/bin/raspiBackup_docker_pre.sh
sudo chmod 755 /usr/local/bin/raspiBackup_docker_post.sh
```
修改配置文件以啟動擴展
```zsh=
sudo nano /usr/local/etc/raspiBackup.conf
```
在最下面加入
```yml=
DEFAULT_EXTENSIONS="temp mem disk execute docker"
```
## 使用
### 手動備份
```zsh=
sudo raspiBackup.sh -g
```
* `-g` - 顯示備份進度

會輸出
```zsh=
--- RBK0009I: pi: raspiBackup.sh V0.6.8 - 2023-04-05 (fc34c30) started at Mon 10 Apr 18:12:31 CST 2023.
--- RBK0116I: Using config file /usr/local/etc/raspiBackup.conf.
--- RBK0096I: Language  not supported.
--- RBK0151I: Using backuppath /backup with partition type ext4.
--- RBK0271I: Smart recycle strategy will be applied.
!!! RBK0157W: No services to stop.
--- RBK0267I: Extension raspiBackup_temp_pre.sh called.
--- RBK0267I: Extension raspiBackup_mem_pre.sh called.
--- RBK0267I: Extension raspiBackup_disk_pre.sh called.
--- RBK0267I: Extension raspiBackup_docker_pre.sh called.
--- RBK2003I: Stopping Docker-Container: pihole portainer
--- RBK0081I: Creating backup of type rsync in /backup/pi/pi-rsync-backup-20230410-181230.
--- RBK0044I: Creating backup of boot partition in /backup/pi/pi-rsync-backup-20230410-181230/pi-backup.img.
--- RBK0045I: Creating backup of partition layout in /backup/pi/pi-rsync-backup-20230410-181230/pi-backup.sfdisk.
--- RBK0046I: Creating backup of master boot record in /backup/pi/pi-rsync-backup-20230410-181230/pi-backup.mbr.
--- RBK0133I: Using directory /backup/pi/pi-rsync-backup-20230410-180057 for hardlinks.
--- RBK0158I: Creating native rsync backup "/backup/pi/pi-rsync-backup-20230410-181230".
--- RBK0085I: Backup of type rsync started. Please be patient.
     24,690,948   0%    1.18MB/s    0:00:19 (xfr#62, to-chk=0/133342)
--- RBK0078I: Backup time: 00:00:27.
--- RBK0033I: Please wait until cleanup has finished.
--- RBK0267I: Extension raspiBackup_temp_post.sh called.
--- RBK1000I: CPU temperature pre and post backup: 50.1'C - 52.5'C
--- RBK0267I: Extension raspiBackup_mem_post.sh called.
--- RBK1001I: Memory usage pre backup - Used: 413 MB Free: 454 MB
--- RBK1001I: Memory usage post backup - Used: 365 MB Free: 418 MB
--- RBK0267I: Extension raspiBackup_disk_post.sh called.
--- RBK1001I: Disk usage pre backup: Used: 7.16 GiB Free: 52.63 GiB
--- RBK1002I: Disk usage post backup: Used: 7.48 GiB Free: 52.31 GiB
--- RBK1003I: Disk usage change: -325.41 MiB (0.00 %%)
--- RBK0267I: Extension raspiBackup_execute_post.sh called.

Broadcast message from pi@pi (somewhere) (Mon Apr 10 18:13:16 2023):

Extension detected raspiBackup.sh succeeded :-)

--- RBK0267I: Extension raspiBackup_docker_post.sh called.
--- RBK2001I: Starting before stopped docker-container: pihole portainer
--- RBK0218I: Applying smart backup strategy. Daily:7 Weekly:4 Monthly:12 Yearly:1.
--- RBK0217I: 1 backups will be smart recycled. 6 backups will be kept. Please be patient.
--- RBK0221I: Smart backup strategy deletes /backup/pi/pi-rsync-backup-20230410-180057.
--- RBK0017I: Backup finished successfully.
--- RBK0010I: pi: raspiBackup.sh V0.6.8 - 2023-04-05 (fc34c30) stopped at Mon 10 Apr 18:13:36 CST 2023 with rc 0.
--- RBK0026I: Debug logfile saved in /backup/pi/pi-rsync-backup-20230410-181230/raspiBackup.log.

```
### 備份還原
待補(目前還不需要)

```
sudo wget -P /usr/local/bin https://raw.githubusercontent.com/framps/raspiBackup/master/helper/raspiBackupRestore2Image.sh
```

```
sudo wget -P /usr/local/bin https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
```

```
sudo chmod 755 /usr/local/bin/raspiBackupRestore2Image.sh
```

```
sudo chmod 755 /usr/local/bin/pishrink.sh
```

## Ref:
* https://github.com/framps/raspiBackup
* https://www.linux-tips-and-tricks.de/en/13-raspberry/443-raspibackup-extensions
* https://github.com/framps/raspiBackup/tree/master/extensions
* https://github.com/framps/raspiBackup/tree/master/extensions_userprovided
* https://www.ewdna.com/2012/04/wget.html
