conanwhf / RaspberryPi-script

RaspberryPi 2-B script

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

希望可以更新一下脚本!

angeluslove opened this issue · comments

我说下我的问题,我使用树莓派3,系统是带界面的官方系统 7月5号的版本。
备份过程中出现了错误,首先是挂载U盘后.img文件超出4G问题,这个我把U盘格式化为了exfat模式。
然后安装了需要的文件,修改了脚本去掉了 -t fat 。可以正常挂载,并建立了一个6G大小的.img

在第二步的时候出错了:
...省略了一些rsync帮助的输出。
Use "rsync --daemon --help" to see the daemon-mode command-line options.
Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.
See http://rsync.samba.org/ for updates, bug reports, and answers
rsync error: syntax or usage error (code 1) at main.c(1640) [Receiver=3.1.1]
./piback.sh: 141: ./piback.sh: --exclude: not found
./piback.sh: 143: ./piback.sh: --exclude: not found
./piback.sh: 145: ./piback.sh: --exclude: not found
./piback.sh: 147: ./piback.sh: --exclude: not found
./piback.sh: 149: ./piback.sh: --exclude: not found
./piback.sh: 151: ./piback.sh: --exclude: not found
./piback.sh: 153: ./piback.sh: --exclude: not found
./piback.sh: 155: ./piback.sh: --exclude: not found
./piback.sh: 157: ./piback.sh: --exclude: not found
./piback.sh: 159: ./piback.sh: --exclude: not found
./piback.sh: 161: ./piback.sh: --exclude: not found
./piback.sh: 163: ./piback.sh: //: Permission denied
ls: cannot access /mnt/backup_root//home/pi/: No such file or directory
...Root partition done
sed: can't read /mnt/backup_root//etc/fstab: No such file or directory
sed: can't read /mnt/backup_root//etc/fstab: No such file or directory
==== All done. You can un-plug the backup device

希望可以得到帮助,这个项目还是很棒的,特别是可以实现官方一样的效果就太酷了!
希望可以更新脚本,维护下项目。

pi@raspberrypi:~ $ sudo ./piback.sh
no argument, assume the mount device is /dev/sda1 ? Y/N
y
FUSE exfat 1.1.0
Reading package lists... Done
Building dependency tree
Reading state information... Done
dosfstools is already the newest version.
kpartx is already the newest version.
parted is already the newest version.
rsync is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
===================== part 1, create a new blank img ===============================
6211636+0 records in
6211636+0 records out
6360715264 bytes (6.4 GB) copied, 3094.85 s, 2.1 MB/s
boot: 8192 >>> 93596, root: 94208 >>> end
mkfs.fat 3.0.27 (2014-11-12)
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
unable to get drive geometry, using default 255/63
mke2fs 1.43.3 (04-Sep-2016)
Creating filesystem with 1540864 4k blocks and 385536 inodes
Filesystem UUID: 523e4157-7d1e-48aa-ae8e-c14192913909
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

===================== part 2, fill the data to img =========================
...Boot partition done
rsync version 3.1.1 protocol version 31
Copyright (C) 1996-2014 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
64-bit files, 64-bit inums, 32-bit timestamps, 64-bit long ints,
socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
append, ACLs, xattrs, iconv, symtimes, prealloc

rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. See the GNU
General Public Licence for details.

rsync is a file transfer program capable of efficient remote update
via a fast differencing algorithm.

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

===================== part 2, fill the data to img =========================
...Boot partition done
rsync version 3.1.1 protocol version 31
Copyright (C) 1996-2014 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
64-bit files, 64-bit inums, 32-bit timestamps, 64-bit long ints,
socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
append, ACLs, xattrs, iconv, symtimes, prealloc

rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. See the GNU
General Public Licence for details.

rsync is a file transfer program capable of efficient remote update
via a fast differencing algorithm.

Usage: rsync [OPTION]... SRC [SRC]... DEST
or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
or rsync [OPTION]... [USER@]HOST:SRC [DEST]
or rsync [OPTION]... [USER@]HOST::SRC [DEST]
or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect
to an rsync daemon, and require SRC or DEST to start with a module name.

Options
-v, --verbose increase verbosity
--info=FLAGS fine-grained informational verbosity
--debug=FLAGS fine-grained debug verbosity
--msgs2stderr special output handling for debugging
-q, --quiet suppress non-error messages
--no-motd suppress daemon-mode MOTD (see manpage caveat)
-c, --checksum skip based on checksum, not mod-time & size
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
--no-OPTION turn off an implied OPTION (e.g. --no-D)
-r, --recursive recurse into directories
-R, --relative use relative path names
--no-implied-dirs don't send implied dirs with --relative
-b, --backup make backups (see --suffix & --backup-dir)
--backup-dir=DIR make backups into hierarchy based in DIR
--suffix=SUFFIX set backup suffix (default ~ w/o --backup-dir)
-u, --update skip files that are newer on the receiver
--inplace update destination files in-place (SEE MAN PAGE)
--append append data onto shorter files
--append-verify like --append, but with old data in file checksum
-d, --dirs transfer directories without recursing
-l, --links copy symlinks as symlinks
-L, --copy-links transform symlink into referent file/dir
--copy-unsafe-links only "unsafe" symlinks are transformed
--safe-links ignore symlinks that point outside the source tree
--munge-links munge symlinks to make them safer (but unusable)
-k, --copy-dirlinks transform symlink to a dir into referent dir
-K, --keep-dirlinks treat symlinked dir on receiver as dir
-H, --hard-links preserve hard links
-p, --perms preserve permissions
-E, --executability preserve the file's executability
--chmod=CHMOD affect file and/or directory permissions
-A, --acls preserve ACLs (implies --perms)
-X, --xattrs preserve extended attributes
-o, --owner preserve owner (super-user only)
-g, --group preserve group
--devices preserve device files (super-user only)
--specials preserve special files
-D same as --devices --specials

上边是第一部分,和第二部分的一部分输出,不明白为什么会打印 rsync 的帮助信息出来。

以树莓派的销量来看,这种需求的人一定不会少,这个脚本还是非常有价值的!

非常感谢你的脚本,经过排错和修改,已经完美备份成功,树莓派3的备份后,写入img到zero中也可以正常启动运行。 以后可以发布自己修改过的镜像了,非常完美!再次感谢你的工作!

sudo rsync --force -rltWDEgopt --delete --stats --progress
最后一个参数和换行标记中间缺少空格
--progress\ 应该修改为 --progress \ ,不然会引起rsync报错,主要是缺少空格后会和后边的参数粘连起来,导致过程报错!

-rltWDEgopt 参数里边的t 重复了,不过不会报错,我不清楚这个是否有影响

sudo apt-get -y install rsync dosfstools parted kpartx exfat-fuse
可以把工具下载的语句添加到最开始,添加exfat-fuse支持挂载exfat格式u盘
然后修改挂载的两个语句为
sudo mount -o uid=1000 /dev/sda1 $usbmount
这样可以支持大于4g的单个img文件

commented

rsync: chown "/mnt/backup_root/opt/Wolfram/WolframEngine/11.0/SystemFiles/Formats/XHTML/.Export.m.Beaje7" failed: Operation not permitted (1) 同步时候出现这个卡住了 你们都遇到过没

可以尝试切换到root再运行脚本!

commented

@angeluslove 好的,谢谢了 刚刚用root备份成功现在实验看看

commented

@angeluslove 恢复镜像写入到别的SD卡 那个根目录cmdline.txt root这里要改吗

@udpsec 我备份后,没有修改过任何东西,可以随意恢复到任何一个设备!

commented

@angeluslove 好的,我是想用U盘启动系统的恢复了结果没点亮 我自己再去研究研究吧。谢谢你解答了

请问,我的系统备份之后可以启动,但是只能用tty1-6的命令行界面,桌面服务是挂掉了,而且startx直接就黑了。这个是什么原因?

@conanwhf 感谢博主的开源,终于搞定了,因为是插在显示屏上而且开机就出问题,报错信息是跳过去看不到了。不过我运行了几次脚本发现在运行第一部分的时候每次产生的文件大小并不是脚本里面的1.3倍,只有大概4G,应该是文件大小被限制了导致文件拷贝不完全,按照上面那个哥么提到的需要删除第60行的-t vfat,就好了。

7个G左右

我在运行脚本前格式化U盘为FAT32格式,最后处理好的镜像都是正好4个G,所以我觉得首先要先格式化为exFAT格式

但是格式成exFAT格式后,出现了这个问题,请问如何解决
FUSE exfat 1.2.5
WARN: volume was not unmounted cleanly.
fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option
mount fail, exit now

好的

@xcxc12344 我之前用的时候也出出fuse这个提示,树莓派系统不支持exfat格式,无法挂载。解决方法就是在命令行下单独运行脚本的第四行安装语句,主要是exfat-fuse,就ok了 应该。

@bearinthesky 好的,我试下

@bearinthesky 你好,我命令行下单独运行脚本的第四行安装语句,还是这个问题:
FUSE exfat 1.2.5
WARN: volume was not unmounted cleanly.
fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option
mount fail, exit now

我的系统是最新的官方界面系统

@xcxc12344 我的好像没出现你这个问题,不太懂。不过你可以就按照这个提示换上这个参数试下,把13行和19行的-o uid=1000改成-o nonempty试一试看行不行,不行可以问下楼上几个哥么都咋处理的。

@conanwhf 博主你好,我在官方2017-07-05-raspbian-jessie的系统上用你的脚本成功制作镜像,写入sd卡成功,一切顺利。
所以应该是系统更新的原因。更新成2017-09-07-raspbian-stretch的版本后失败了。

@xcxc12344 暂时不会去更新最新的stretch系统,尝试了一下放弃了,很多软件都有安装错误,根本玩不转,打算还是使用jessie,稳定!

看了评论,最新的stretch系统无法使用这个脚本备份SD卡吗?

stretch不能用。用这脚本备份成img,恢复时烧到卡里不能启动。

从baidu搜到这里。学习了一下脚本,使用树莓派3b stretch 测试了一下,应该是可用的。我改了一下,变成备份到本地。希望帮忙测试一下是否其他情况可用:https://github.com/cwt0490/rpi-bk

之前修改过程中遇到的主要问题:1. 不能备份到curlftpfs加载的ftp mount点。因为ftp下无法加载img文件
2. img文件空间不足,由1.2->1.5后没有问题。实际恢复后会比原路径多一些·空间占用(目前不知道为什么)

感谢作者的分享。
我在树莓派zero上使用这个脚本基本上没有大问题。
我的是从大TF卡,换成小TF卡(32G -> 16G)
系统版本:
pi@raspi_zero:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.1 (stretch)
Release: 9.1
Codename: stretch
pi@raspi_zero:~$


但是还有一个小问题,就是使用 Win32DiskImager Wirte 之后, 启动了树莓派,
就是分区空间检查了一下不太对
pi@raspi_zero:~$ df -BM
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/root 2691M 2194M 341M 87% /
devtmpfs 213M 0M 213M 0% /dev
tmpfs 218M 0M 218M 0% /dev/shm
tmpfs 218M 6M 212M 3% /
tmpfs 5M 1M 5M 1% //lock
tmpfs 218M 0M 218M 0% /sys/fs/cgroup
/dev/mmcblk0p1 42M 21M 21M 51% /boot
tmpfs 44M 0M 44M 0% //user/1000
pi@raspi_zero:~$


可以看到 /dev/root mount / 之后3GB, 想要的情况应该是至少有12GB以上用于该分区才是。

目前我还在寻找原因和解决方法中。
不知道作者和其它朋友有没有什么指教???
谢谢


=========================
谢谢 @cwt0490 的回复。根据你说的可以使用命令拓展磁盘空间,于是我上网找了相关命令,
在这里找到了使用原本自带的 树莓派 config 软件即可恢复正常,
恢复之后空间如下:
pi@raspi_zero:~$ df -BG
Filesystem 1G-blocks Used Available Use% Mounted on
/dev/root 15G 3G 12G 16% /
devtmpfs 1G 0G 1G 0% /dev
tmpfs 1G 0G 1G 0% /dev/shm
tmpfs 1G 1G 1G 3% /run
tmpfs 1G 1G 1G 1% /run/lock
tmpfs 1G 0G 1G 0% /sys/fs/cgroup
/dev/mmcblk0p1 1G 1G 1G 51% /boot
tmpfs 1G 0G 1G 0% /run/user/1000
pi@raspi_zero:~$

参考的内容如下:
https://raspberrypi.stackexchange.com/questions/499/how-can-i-resize-my-root-partition#answer-946


其实我是知道树莓派自带的这个 raspi-config 软件,以及里面有一个充分利用sd卡空间的选项,只不过正常第一次装系统容量都够用。看上去系统是默认保留了一点点容量出来,所以有了 raspi-config 这个软件中的一个选项可以把保留的空间都用进去。
倒是没想到在这种情况下也可以使用

root空间是默认磁盘空间的1.2倍,恢复后需要使用命令扩展磁盘空间。树莓派3b上有工具,zero就不清楚了。

博主弃坑了,我基于这个小小修改了一下...目前自用一切正常...等我捋捋提交一下...

https://github.com/elespec/rpi-backup 基于博主的版本,做了细微的调整;

真是不好意思,今年怀孕生娃搞得手忙脚乱,无奈弃坑…正好看到你的留言,感谢贡献! 发自我的 iPhone

在 2018年11月20日,18:09,elespec @.***> 写道: 博主弃坑了,我基于这个小小修改了一下...目前自用一切正常...等我捋捋提交一下... — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

祝大神生娃,带娃,养娃一切顺利,祝娃健康成长,项目我拷走自用了,我会署名来源的;