Files
hugo_blog.awin.one/content/posts/2024/2024-01-08_線上備份樹莓派/index.md

61 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
slug: 線上備份樹莓派
title: 線上備份樹莓派
description:
toc: true
authors: [awin]
tags: [raspberrypi]
categories: [system]
series: [Raspberry Pi]
date: 2024-01-08T00:00:00
lastmod: 2024-01-08T00:00:00
featuredVideo:
featuredImage:
draft: false
enableComment: true
---
`image-backup``image-utils` 裡面的一個工具,可以直接把樹莓派系統直接備份到另一個檔案,不用拔卡或是關機,非常方便。
<!--more-->
`image-utils` 的Github repo在[seamusdemora/RonR-RPi-image-utils: tools to create a backup of a running Raspbian system to an SD card image file](https://github.com/seamusdemora/RonR-RPi-image-utils)
## 安裝 `image-utils`
```shell
cd && mkdir ~/image-utilities && cd ~/image-utilities
wget -O image.zip "https://forums.raspberrypi.com/download/file.php?id=63044&sid=58c9d2d90272e5ae96c12a58a30731d9"
unzip ./image.zip
chmod a+x image-*
```
## 備份
`~/image-utilities` 目錄下執行 `image-backup` 會以對話的方式來備份,像是這樣:
```shell
sudo ./image-backup
Image file to create? /media/backup/pi4_sd_backup.img ## 輸入檔案路徑,例子是/media/backup/pi4_sd_backup.img
Initial image file ROOT filesystem size (MB) [11631]? ## 按 Enter 跳過,使用 default 值
Added space for incremental updates after shrinking (MB) [0]? ## 按 Enter 跳過,使用 default 值
Create /media/backup/pi4_sd_backup.img (y/n)? y ## 按 y
```
然後就會開始備份系統,過程會花上一些時間,取決於你的系統大小與檔案寫的速度。
## 自動備份
但是這樣每次都要手動操作很麻煩,像下面這樣一個命令解決比較方便:
```shell
sudo ./image-backup -i /media/backup/pi4.img
```
這樣就可以透過`crontab`自動執行了。
## 增量備份
如果已經備份過系統,下次備份的時候有指定上一次的備份檔,就會做增量備份,如下:
```shell
sudo ./image-backup /media/upload/pi4.img
```
注意沒有 `-i` 這個選項。