无法备份系统解决方法
操作步骤
- 打开,复制,使用VScode设置编码:UTF-8 without BOM,换行符:LF(Linux 格式),保存为 raspiBackup.sh
https://raw.githubusercontent.com/framps/raspiBackup/master/raspiBackup.sh - 用 WinSCP / FileZilla / MobaXterm 等 SFTP 工具上传到树莓派
chmod +x raspiBackup.sh - 准备 U 盘(假设为 /dev/sda1)
- 格式化为 ext4(卷标 RPiBackup 方便识别)
sudo mkfs.ext4 -L RPiBackup /dev/sda1 - 创建挂载点
sudo mkdir -p /mnt/backup_disk - 临时挂载测试
sudo mount /dev/sda1 /mnt/backup_disk - 手动备份
sudo ./raspiBackup.sh /mnt/backup_disk
出现的问题
lnh@lnh:~ $ sudo ./raspiBackup.sh /mnt/backup_disk
--- RBK0009I: lnh: raspiBackup.sh V0.7.2 - D a t e Date Date (Sha1$) started at Fri 26 Dec 22:27:44 CST 2025
--- RBK0031I: Checking whether a new version of raspiBackup.sh is available
Unsupported version of raspiBackup.sh
??? RBK0019E: Missing option -a and -o
--- RBK0033I: Please wait until cleanup has finished
--- RBK0320I: Removing incomplete backup. This may take some time. Please be patient
Backup finished with warnings. Check previous warning messages for details
??? RBK0005E: Backup failed. Check previous error messages for details
--- RBK0010I: lnh: raspiBackup.sh V0.7.2 - D a t e Date Date (Sha1$) stopped at Fri 26 Dec 22:27:47 CST 2025 with rc 107
--- RBK0026I: Debug logfile saved in /home/lnh/raspiBackup.log
其中看log文件
20251226-222747 DBG 8261: --- rsync version: 3.4.1
??? RBK0019E: Missing option -a and -o
20251226-222747 DBG 2784: --> exitError 107
20251226-222747 DBG 2791: <-- exitError 107
20251226-222747 DBG 5482: --> cleanup
--- RBK0033I: Please wait until cleanup has finished
20251226-222747 DBG 2281: --> logSystemServices
20251226-222747 DBG 2285: <-- logSystemServices
20251226-222747 DBG 3795: --> startServices
20251226-222747 DBG 2281: --> logSystemServices
20251226-222747 DBG 2285: <-- logSystemServices
20251226-222747 DBG 3821: <-- startServices
20251226-222747 DBG 3825: --> executeAfterStartServices
20251226-222747 DBG 3838: <-- executeAfterStartServices
20251226-222747 DBG 5799: --> cleanupBackup
20251226-222747 DBG 5199: --> cleanupBackupDirectory
20251226-222747 DBG 5201: --- Checking /mnt/backup_disk/@HOSTNAME@/tmp for clean up
--- RBK0320I: Removing incomplete backup. This may take some time. Please be patient
20251226-222747 DBG 5215: --- Deleting /mnt/backup_disk/@HOSTNAME@/tmp
rmdir: failed to remove '/mnt/backup_disk/@HOSTNAME@/tmp': No such file or directory
20251226-222747 DBG 5219: <-- cleanupBackupDirectory
20251226-222747 DBG 5814: --> cleanupTempFiles
20251226-222747 DBG 5826: <-- cleanupTempFiles
20251226-222747 DBG 5808: <-- cleanupBackup
20251226-222747 DBG 5814: --> cleanupTempFiles
20251226-222747 DBG 5826: <-- cleanupTempFiles
20251226-222747 DBG 3778: --> finalCommand
20251226-222747 DBG 3790: <-- finalCommand
20251226-222747 DBG 5550: --- Terminate now with rc 107
Backup finished with warnings. Check previous warning messages for details
??? RBK0005E: Backup failed. Check previous error messages for details
--- RBK0010I: @HOSTNAME@: raspiBackup.sh V0.7.2 - D a t e Date Date (Sha1$) stopped at Fri 26 Dec 22:27:47 CST 2025 with rc 107
20251226-222748 DBG 5071: --> sendEMail
20251226-222748 DBG 5193: <-- sendEMail
20251226-222748 DBG 5316: --- Masquerading some mount options
20251226-222748 DBG 5371: --- Masquerading home directory name
20251226-222748 DBG 5376: --- Masquerading hostname
20251226-222748 DBG 5382: --- Masquerading sensitive non local IPs
20251226-222748 DBG 2352: --> logFinish
20251226-222748 DBG 2363: --- 107 2 0
20251226-222748 DBG 2368: --- LOG_OUTPUT=3
20251226-222748 DBG 2372: --- LOG_OUTPUT: 3
20251226-222748 DBG 2399: --- DEST_LOGFILE: /home/lnh/raspiBackup.log
20251226-222748 DBG 2400: --- DEST_MSGFILE: /home/lnh/raspiBackup.msg
20251226-222748 DBG 2408: --- Moving Logfile: /tmp/raspiBackup.log to /home/lnh/raspiBackup.log
20251226-222748 DBG 2412: --- Logfile used: /home/lnh/raspiBackup.log
20251226-222748 DBG 2420: --- Moving Msgfile: /tmp/raspiBackup.msg to /home/lnh/raspiBackup.msg
20251226-222748 DBG 2424: --- Msgfile used: /home/lnh/raspiBackup.msg
20251226-222748 DBG 2431: *** cat /tmp/raspiBackup.logf
20251226-222748 DBG 2431:
20251226-222748 DBG 2446: <-- logFinish
20251226-222748 DBG 5419: --> callNotificationExtension 107
20251226-222748 DBG 2471: --> callExtensions notify
20251226-222748 DBG 2543: <-- callExtensions
20251226-222748 DBG 5428: --- NotificationExtension rc: 0
20251226-222748 DBG 5433: <-- callNotificationExtension 0
20251226-222748 DBG 5648: <-- cleanup
20251226-222748 DBG 5475: --> unLockMe
20251226-222748 DBG 5477: <-- unLockMe
??? RBK0019E: Missing option -a and -o
缺失参数??
使用sudo ./raspiBackup.sh -h
查看官方文档
bash
raspiBackup.sh 0.7.2, $Date$/Date$ - Sha1$
Usage: raspiBackup.sh [option]* {backupDirectory}
-通用选项-
-b {dd block size} (Default: 1MB)设置dd命令的块大小
-D {additional dd parameters} (Default: no)指定dd命令的额外参数
-e {email address} (Default: no)指定接收备份通知的邮箱地址
-E {additional email call parameters} (Default: no)指定发送邮件时的额外参数
-f {config filename}指定自定义配置文件路径
-g Display progress bar 显示备份进度条
-G {message language} (EN DE FI FR) (Default: EN)设置消息显示语言(可选:EN/英语、DE/德语、FI/芬兰语、FR/法语)
-h display this help text 显示本帮助信息
-l {log level} (Debug|Off) (Default: Debug)设置日志级别(可选:Debug/调试模式、Off/关闭)
-L {log targetdirectory} (Current|Backup|Varlog) (Default: Backup)设置日志存储位置(可选:Current/当前目录、Backup/备份目录、Varlog/系统日志目录)
-m {message level} (Detailed|Minimal) (Default: Minimal)设置备份过程中消息输出的详细程度(可选:Detailed/详细模式、Minimal/精简模式)
-M {backup description of snapshot}为本次备份快照添加自定义描述(便于识别备份用途)
-s {email program to use} (mail,ssmtp,msmtp,sendEmail,mailext) (Default: mail)指定发送邮件通知的程序(可选:mail、ssmtp、msmtp、sendEmail、mailext)(默认值:mail)
--timestamps Prefix messages with timestamps (Default: no)为所有输出消息添加时间戳前缀(默认值:否)
-u {excludeList} List of directories to exclude from tar and rsync backup指定在tar/rsync备份中需要排除的目录列表(多个目录用空格分隔)
-U current script version will be replaced by the most recent version. Current version will be saved and can be restored with parameter -V 将当前脚本版本替换为最新版本;当前版本会被保存,可通过`-V`参数恢复
-v verbose output of backup tools (Default: no)让备份工具输出详细日志(默认值:否)
-V restore a previous version 恢复之前保存的脚本版本
-备份选项-
-a {commands to execute after Backup} (Default: no)指定备份完成后要执行的自定义命令
-B Save bootpartition in tar file (Default: 0)将引导分区(boot分区)保存为tar文件
-F Backup is simulated 模拟备份(仅执行备份流程但不实际生成备份文件,用于测试)
--ignoreAdditionalPartitions (Default: no) - Partitionnumbers > 2 will not be saved 忽略编号大于2的分区(默认值:否)------仅备份前2个分区,其余分区不保存
--ignoreMissingPartitions (Default: no) - Allow to backup not all previously saved paritions 忽略缺失的分区(默认值:否)------允许不备份所有历史备份过的分区(适配分区变动场景)
-k {backupsToKeep} (Default: 3) 设置本地保留的备份文件数量(超出则自动删除旧备份)(默认值:3)
-o {commands to execute before Backup} (Default: no) 指定备份开始前要执行的自定义命令(如停止数据库服务)(默认值:无)
-P use partitionoriented backup mode to backup the first two partitions (Default: 1 2) 使用「分区导向备份模式」备份前两个分区(默认值:1 2,即备份分区1和2)
-t {backupType} (dd|rsync|tar) (Default: rsync) 指定备份方式(可选:dd/整盘镜像、rsync/增量同步、tar/归档打包)(默认值:rsync)
-T {List of partitions to backup in partition oriented mode} (Partition numbers, e.g. "1 2 3" or "*" for all) (Default: 1 2) 指定分区导向模式中要备份的分区编号(例如"1 2 3",或"*"表示所有分区)(默认值:1 2)
--tarCompressionTool {tar Comressiontool} (bzip2,gzip,lzip,lzma,lzop,xz,zstd) 指定tar备份文件的压缩工具(可选:bzip2、gzip、lzip、lzma、lzop、xz、zstd)
--tarCompressionToolOptions {Options for tar compressiontool} 指定上述压缩工具的自定义参数(如gzip的"-9"表示最高压缩比)
-z compress DD and TAR backup file with gzip (Default: no) 使用gzip压缩DD/TAR格式的备份文件(默认值:否)
-恢复选项-
-0 Restore device will not be partitioned 不对恢复目标设备进行分区操作(保留设备原有分区结构)
-00 Restored partitions will not be formatted (only for backup type rsync) 不对恢复后的分区进行格式化(仅适用于rsync类型的备份)
-1 Formatting errors on restore device will be ignored 格式化恢复分区时检测磁盘坏块(默认值:否)
-C Formating of the restorepartitions will check for badblocks (Default: no) 指定备份恢复的目标设备(默认值:无)(示例:/dev/sda,即SD卡/U盘设备名)
-d {restoreDevice} (Default: no) (Example: /dev/sda) 指定恢复后的根分区路径(默认值:恢复目标设备)(示例:/dev/sdb1)
-R {rootPartition} (Default: restoreDevice) (Example: /dev/sdb1) 指定恢复后的根分区路径(默认值:恢复目标设备)(示例:/dev/sdb1)
-T {List of partitions to restore from a partition oriented backup} (Partition numbers, e.g. "1 2 3" or "*" for all) (Default: 1 2) 指定从分区导向备份中恢复的分区编号(例如"1 2 3",或"*"表示所有分区)(默认值:1 2)
--resizeRootFS|resizeLastPartitionFS (Default: yes) 恢复完成后自动扩容根分区/最后一个分区的文件系统(适配更大容量的SD卡)(默认值:是)
这个版本好像不是最新的,想办法升级成最新版的,下载raspiBackup.sh
curl -o install -L https://raw.githubusercontent.com/framps/raspiBackup/master/installation/install.sh; sudo bash ./install
- 使用 方向键 ↑↓ 移动
- 按 空格键 选中(复选框)
- 按 Tab 键 切换到 /
- 按 Enter 确认
具体配置内容根据自己需要进行配置,每个配置都有相应的网址进行说明
我选择
Select backup type : dd/ddz 必须选这个才能生成完整镜像
Use compression for dd backup? Yes 启用 gzip 压缩(即 -z)
Backup target directory /mnt/backup_disk 你的 U 盘路径
Number of backups to keep 3 64GB U 盘可存压缩镜像数量
Send email on completion? No(除非你配置了邮件)
Language for messages Chinese
需要处理的服务:一定要选cron ,选择完成
恭喜! raspiBackup 安装成功.
接下来你可以:
1) 在终端输入 raspiBackup开始备份
2) 在终端输入 raspiBackup 还原备份到SD卡
3) 校验备份文件.
4) 参考FAQ页面 https://www.linux-tips-and-tricks.de/en/faq
5) 进行设置和微调项 raspiBackup
https://www.linux-tips-and-tricks.de/en/raspibackup#parameters
6) 开启定期备份
7) 访问https://www.linux-tips-and-tricks.de/en/backup 获取更多raspiBackup信息
确认挂载的U盘df -h /mnt/backup_disk/
执行备份sudo raspiBackup.sh
出现错误/usr/local/bin/raspiBackup.sh: line 11070: syntax error: unexpected end of file
--- RBK0026I: Debug logfile saved in /home/lnh/raspiBackup.log
查看文件sudo ls -al /usr/local/bin/
sudo ls -al /usr/local/bin/
total 612
drwxr-xr-x 2 root root 4096 Dec 26 23:50 .
drwxr-xr-x 11 root root 4096 Dec 4 22:38 ...
lrwxrwxrwx 1 root root 29 Dec 26 23:50 raspiBackup -> /usr/local/bin/raspiBackup.sh
lrwxrwxrwx 1 root root 38 Dec 26 23:50 raspiBackupInstallUI -> /usr/local/bin/raspiBackupInstallUI.sh
-rwxr-xr-x 1 root root 188980 Dec 26 23:44 raspiBackupInstallUI.sh
-rwxr-xr-x 1 root root 425786 Dec 26 23:50 raspiBackup.sh
删除脚本重新生成sudo rm -rf /usr/local/bin/raspiBackup.sh
执行导入脚本sudo raspiBackupInstallUI
进行备份sudo raspiBackup
??? RBK1004E: bc not found. Please install bc first with with 'sudo apt-get install bc'.
安装必要依赖sudo apt-get install bc
如果安装msmtprc,需要将.msmtprc复制到/root/下
bash
# 复制你的 msmtp 配置到 root 家目录
sudo cp ~/.msmtprc /root/.msmtprc
sudo chmod 600 /root/.msmtprc
验证 /usr/sbin/sendmail 是否指向 msmtp,使用mail -s
ls -l /usr/sbin/sendmail
lrwxrwxrwx 1 root root 26 Dec 27 01:20 /usr/sbin/sendmail -> /usr/bin/msmtp
如果不是
sudo ln -sf /usr/bin/msmtp /usr/sbin/sendmail
测试
echo "Test" | sudo mail -s "Test" 你的qq@qq.com
收到邮件后再次运行备份:sudo raspiBackup
成功备份树莓派!!!