基本用法:tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /
选项解释:
c创建归档
v啰嗦模式,打印详细的压缩过程
p保持文件的权限,以便将来恢复
z 指定用 gzip 压缩
f 指定备份文件名
--exclude=指定要排除的文件或目录,至少要排除掉备份文件本身
--one-file-system只备份根目录,排除掉所有别的文件系统,包括挂载的其它分区。
例如:/home /sys /proc /run /dev /media /指定备份的目标,这里就是根目录tar 的选项可以以短横开头,也可以省略短横。如果使用了短横的话,f选项必需位于最后,后面跟着压缩文件名。
它实际上是参数,而不是选项。
变形, 使用 xz 或 bzip2 压缩:
tar -cvpjf backup.tar.xz --exclude=/backup.tar.xz --one-file-system /
如果 /home, /boot 等目录位于不同的分区,使用 --one-file-system 会将它们排除掉,如果要包含这些目录,只能省略掉 --one-file-system 选项,再用 --exclude 分别指定要排除的目录:
cd / # 这一步很重要,下面的长命令行假定从 / 运行
tar -cvpzf backup.tar.gz \
--exclude=/backup.tar.gz \
--exclude=/proc \
--exclude=/tmp \
--exclude=/mnt \
--exclude=/dev \
--exclude=/sys \
--exclude=/run \
--exclude=/media \
--exclude=/var/log \
--exclude=/var/cache/apt/archives \
--exclude=/usr/src/linux-headers* \
--exclude=/home/*/.gvfs \
--exclude=/home/*/.cache \
--exclude=/home/*/.local/share/Trash /
1,Backup rootfs
Run the following commands on your target board. These commands will back up the entire root partition:
sudo passwd root
su root
cd /
tar --warning=no-file-changed -cvpzf /rootfs.tar.gz \
--exclude=/rootfs.tar.gz --exclude=/var/lib/docker/runtimes \
--exclude=/etc/firstuser --exclude=/etc/friendlyelec-release \
--exclude=/usr/local/first_boot_flag --one-file-system /
2, Extract the rootfs.tar.gz exported in the previous section, the tar command requires root privileges, so you need put sudo in front of the command:
mkdir debian-buster-desktop-arm64/rootfs
sudo tar xvzfp rootfs.tar.gz -C debian-buster-desktop-arm64/rootfs --numeric-owner --same-owner
3,Make rootfs to img:
sudo ./build-rootfs-img.sh debian-buster-desktop-arm64/rootfs debian-buster-desktop-arm64
4, Go into debian-buster-desktop-arm64 folder, and copy rootfs.img and parameter.txt files into tf card. and to replace the older files.