GithubHelp home page GithubHelp logo

unconnectedbedna / shrink-backup Goto Github PK

View Code? Open in Web Editor NEW
45.0 5.0 6.0 376 KB

A utility to backup SBC:s (like Raspberry pi) into minimal bootable img files

License: Other

Shell 100.00%
archlinuxarm-rpi armbian backup linux manjaro-arm raspberry-pi sbc backup-script backup-tool backup-utility

shrink-backup's People

Contributors

unconnectedbedna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

shrink-backup's Issues

Boot from a backup created from an RPI3 running RaspbianOS 32 lite fails with "ALERT! PARTUUID=a1f2b077-02 does not exist. Dropping to a shell!"

I created a backup successfully for the system mentioned in the issue title.

When I started the restored backup (restored with dd) I get

Begin: Running /scripts/local-block ... done.
Begin: Running /scripts/local-block ... done.
Begin: Running /scripts/local-block ... done.
Begin: Running /scripts/local-block ... done.
Begin: Running /scripts/local-block ... done.
Begin: Running /scripts/local-block ... done.
Begin: Running /scripts/local-block ... done.
done.
Gave up waiting for root file system device. 
...
ALERT! PARTUUID=a1f2b077-02 does not exist. Dropping to a shell!

I checked the backup image and get

sudo blkid
/dev/sdc1: UUID="BDDC-31AC" TYPE="vfat" PARTUUID="966ad0d3-01"
/dev/sdc2: UUID="b4f05dfa-8a60-47e8-a6f2-f923d6d339dc" TYPE="ext4" PARTUUID="966ad0d3-02"

There is indeed no PARTUUID a1f2b077-02.

shrink-backup.log
In the debug log PARTUUID a1f2b077-02 is used. But the created backup image has PARTUUID="966ad0d3-02".

Backup fails when system is not on first mmcblk device

Describe the bug

Hi! I have an arm64 SBC with onboard eMMC running ubuntu-rockchip 22.04.3 LTS.
For the convenience of testing kernel driver, I am currently using SD card instead of the eMMC.

I happened to find this project can be an alternative to the rpi-clone when I move to other SBCs or system. But when I tried to backup the system on SD card (mmcblk1), the script did not skip unmounted empty disks (mmcblk0/eMMC), which caused dd and sfdisk to fail. After I manually modify the script to specify HD_DEV_PATH="/dev/mmcblk1", it works.

# main branch

2023-11-01 12:46:19 [INFO] - Using dd to create bootsector, bs=512 count=255
------------------------------------------------------------------------------
2023-11-01 12:46:19 [DEBUG] - Running: dd bs=512 count=255 if=/dev/mmcblk0
/dev/mmcblk0boot0
/dev/mmcblk0boot1
/dev/mmcblk1 of=/mnt/sda/backup.img conv=noerror,sync status=progress
dd: failed to open '/dev/mmcblk0'$'
''/dev/mmcblk0boot0'$'
''/dev/mmcblk0boot1'$'
''/dev/mmcblk1': No such file or directory
------------------------------------------------------------------------------
2023-11-01 12:46:21 [INFO] - Using truncate to resize img file to 40211MB
2023-11-01 12:46:21 [DEBUG] - Running: truncate --size=42164379136 /mnt/sda/backup.img
2023-11-01 12:46:22 [INFO] - Using losetup -P to loop /mnt/sda/backup.img
2023-11-01 12:46:22 [DEBUG] - Running: losetup -P /dev/loop0 /mnt/sda/backup.img
2023-11-01 12:46:23 [INFO] - Using sfdisk to remove root partition
2023-11-01 12:46:23 [DEBUG] - 1 partition detected, setting LOOP0=/dev/loop0p1
------------------------------------------------------------------------------
2023-11-01 12:46:23 [ERROR] - SFDISK FAILED:
sfdisk: /dev/loop0: partition 1: failed to delete
------------------------------------------------------------------------------
2023-11-01 12:46:23 [ERROR] - Cleanup function called with non zero exit code: exit 1
2023-11-01 12:46:23 [DEBUG] - Removing loop0 in cleanup function: losetup -d /dev/loop0
2023-11-01 12:46:23 [INFO] - Elapsed time: 00.07
2023-11-01 12:46:23 [DEBUG] - Exiting script

# testing branch

2023-11-01 15:24:11 [INFO]  - Using dd to create bootsector
------------------------------------------------------------------------------
2023-11-01 15:24:11 [DEBUG] - Running: dd bs=512 count=255 if=/dev/mmcblk0
/dev/mmcblk0boot0
/dev/mmcblk0boot1
/dev/mmcblk1 of=/mnt/sda/backup1.img conv=noerror,sync status=progress
dd: failed to open '/dev/mmcblk0'$'
''/dev/mmcblk0boot0'$'
''/dev/mmcblk0boot1'$'
''/dev/mmcblk1': No such file or directory
------------------------------------------------------------------------------
2023-11-01 15:24:13 [INFO]  - Using truncate to resize img file' to 40046MB
2023-11-01 15:24:13 [DEBUG] - Running: truncate --size=41991589376 /mnt/sda/backup1.img
2023-11-01 15:24:14 [INFO]  - Looping img file
2023-11-01 15:24:14 [DEBUG] - Running function: do_loop
2023-11-01 15:24:15 [DEBUG] - Running: losetup -P /dev/loop0 /mnt/sda/backup1.img
2023-11-01 15:24:16 [INFO]  - Using sfdisk to remove root partition
2023-11-01 15:24:16 [DEBUG] - Running: sfdisk --delete -f /dev/loop0
------------------------------------------------------------------------------
2023-11-01 15:24:16 [ERROR] - SFDISK FAILED:
sfdisk: failed to parse partition number: ''
------------------------------------------------------------------------------
2023-11-01 15:24:16 [ERROR] - Cleanup function called with non zero exit code: exit 1
2023-11-01 15:24:17 [DEBUG] - Removing loop0 in cleanup function: losetup -d /dev/loop0
2023-11-01 15:24:17 [INFO]  - Elapsed time: 00.08
2023-11-01 15:24:17 [DEBUG] - Exiting script

Harware (please complete the following information):

  • OS: Ubuntu (preinstalled image)
  • Version: 22.04.3 LTS aarch64

Additional context
shrink-backup.log.txt

$ lsblk
NAME         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
mtdblock0     31:0    0    16M  0 disk <= onboard SPI flash, not used
mmcblk0      179:0    0 230.5G  0 disk <= onboard eMMC flash, no system, not mounted
mmcblk0boot0 179:32   0     4M  1 disk
mmcblk0boot1 179:64   0     4M  1 disk
mmcblk1      179:96   0 238.3G  0 disk <= SD card, system
├─mmcblk1p1  179:97   0   512M  0 part /boot/firmware
└─mmcblk1p2  179:98   0 237.8G  0 part /

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           1.6G  3.4M  1.6G   1% /run
/dev/mmcblk1p2  234G   37G  188G  17% /
tmpfs           7.8G     0  7.8G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/mmcblk1p1  512M  101M  412M  20% /boot/firmware
tmpfs           1.6G   76K  1.6G   1% /run/user/129
tmpfs           1.6G   68K  1.6G   1% /run/user/1000

$ fdisk -l
Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/mtdblock0: 16 MiB, 16777216 bytes, 32768 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mmcblk0: 230.47 GiB, 247463936000 bytes, 483328000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mmcblk1: 238.3 GiB, 255869321216 bytes, 499744768 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 33EC80F7-D4F2-4D42-A2EE-964C3CBCCFF6

Device           Start       End   Sectors   Size Type
/dev/mmcblk1p1   32768   1081343   1048576   512M Linux extended boot
/dev/mmcblk1p2 1081344 499744734 498663391 237.8G Linux filesystem

Testing branch: shrink-backup.conf <> exclude.txt

Hello,

Downloaded the latest shrink-backup from tesing branch to continue some tests regarding umount issue.

Started shrink-backup with option -t which means

  -t            Use exclude.txt in same folder as script to set excluded directories
                  One directory per line: "/dir" or "/dir/*" to only exclude contents

The shrink-backup folder looks like this (exclude.txt exists):

-rw-r--r-- 1 1024 users 11885129216 Jul 25 23:59 backup_george_bookworm.img
-rw-r--r-- 1 1024 users          83 Aug  1  2023 exclude.txt
-rw-r--r-- 1 1024 users        1539 Jun 25 17:20 LICENSE
-rw-r--r-- 1 1024 users       18192 Jun 25 17:00 README.md
-rwxr-xr-x 1 1024 users       99071 Jun 25 16:58 shrink-backup
-rw-r--r-- 1 1024 users        3342 Aug  6 21:51 shrink-backup.log
-rwxr-xr-x 1 1024 users      100836 Aug  6 21:44 shrink-backup-testing

But shrink-backup drops an error:

pi@george:/mnt/netbackup/shrink-backup $ sudo /mnt/netbackup/shrink-backup/shrink-backup-testing -atlz /mnt/netbackup/shrink-backup/backup_george_bookworm.img
## Debugging requested, writing to log file: /mnt/netbackup/shrink-backup/shrink-backup.log
## Zoom speed requested...
## Scanning filesystem and calculating...
!! ERROR! -f selected but shrink-backup.conf does not exist!

I did not select an -f option.

Log-File:

2024-08-06 22:01:12 [INFO]  - Debugging requested, writing to log file /mnt/netbackup/shrink-backup/shrink-backup.log
2024-08-06 22:01:12 [INFO]  - Script started with: /mnt/netbackup/shrink-backup/shrink-backup-testing -atlz /mnt/netbackup/shrink-backup/backup_george_bookworm.img
2024-08-06 22:01:12 [INFO]  - Zoom speed requested, setting SLEEPING to empty variable | ZOOM=true
2024-08-06 22:01:12 [INFO]  - -a selected by user, setting ADDED_SPACE to 0 (non-zero value)
2024-08-06 22:01:12 [DEBUG] - ADDED_SPACE=0
2024-08-06 22:01:12 [INFO]  - f2fs root filesystem detected
2024-08-06 22:01:12 [DEBUG] - FSTYPE=f2fs
2024-08-06 22:01:13 [DEBUG] - LOCAL_DEV_PTUUID=655d03f1 | LOCAL_DEV_PATH=/dev/mmcblk0
2024-08-06 22:01:13 [INFO]  - f2fs filesystem or conversion to f2fs requested, disabling autoexpansion
------------------------------------------------------------------------------
2024-08-06 22:01:13 [DEBUG] - IMG_FILE=/mnt/netbackup/shrink-backup/backup_george_bookworm.img
2024-08-06 22:01:13 [DEBUG] - PARTITION_TABLE=msdos
2024-08-06 22:01:13 [DEBUG] - UPDATE=false
2024-08-06 22:01:13 [DEBUG] - AUTORESIZE_RUN=true
2024-08-06 22:01:13 [DEBUG] - PROMPTS=true
2024-08-06 22:01:13 [DEBUG] - EXCLUDE_FILE=true
2024-08-06 22:01:14 [DEBUG] - AUTOEXPAND=false
2024-08-06 22:01:14 [DEBUG] - RSYNC_DELETE=--delete
2024-08-06 22:01:14 [DEBUG] - F2FS=false
2024-08-06 22:01:14 [DEBUG] - TTY_AVAILABILITY=/dev/tty
------------------------------------------------------------------------------
2024-08-06 22:01:14 [INFO]  - -f selected by user, using /mnt/netbackup/shrink-backup/shrink-backup.conf
2024-08-06 22:01:14 [ERROR] - shrink-backup.conf does not exist, exit 3

A command
$ cp exclude.txt shrink-backup.conf
solves the problem.

Is exclude.txt now replaced by shring-backup.conf ?

Orange Pi 5 success

REPORT: this app works very well with the Orange Pi 5 of which I'm just preparing to upload an MX Linux respin (Xfce) where I locate it in the main Menu along with a help doc.

https://github.com/jerry3904/OrangePi_respin

The significance of this success lies in the fact that no other method I've tried or found mentioned online has worked. I would think you might want to add that to your "Experimental" section at least.

Unable to run as cronjob

Describe the bug
Script works fine in CLI, but unable to make it work as cronjob

To Reproduce

sudo crontab -e
0 2 * * * backup -aytl /backup/pi.img

Expected behavior
Was expecting it to work the same as CLI

Harware (please complete the following information):

  • Hardware: Raspberry Pi 4B 4GB RAM
  • OS: DietPi (Bookworm) on SD card

Additional context
First of all thank you very much for this wonderful script. This is just a small inconvenience. Asking here just in case this is a simple fix.
Here is a log of a failed attempt at cronjob

2024-05-24 00:35:01 [INFO]  - Debugging requested, writing to log file /home/backup/shrink-backup.log
2024-05-24 00:35:01 [INFO]  - ext4 root filesystem detected
2024-05-24 00:35:01 [DEBUG] - FSTYPE=ext4
2024-05-24 00:35:01 [DEBUG] - LOCAL_DEV_PTUUID=28a6ec92 | LOCAL_DEV_PATH=/dev/mmcblk0
2024-05-24 00:35:01 [DEBUG] - PARTITION_TABLE=
2024-05-24 00:35:01 [DEBUG] - Update existing img file, UPDATE=false
2024-05-24 00:35:01 [DEBUG] - Requesting size from resize2fs, RESIZE2FS_RUN=true
2024-05-24 00:35:01 [DEBUG] - Prompt for user confirmation, PROMPTS=false
2024-05-24 00:35:01 [DEBUG] - Auto expansion, AUTOEXPAND=true
2024-05-24 00:35:01 [INFO]  - -a selected by user
2024-05-24 00:35:01 [DEBUG] - ADDED_SPACE=0
2024-05-24 00:35:01 [INFO]  - Executing make_img function
------------------------------------------------------------------------------
2024-05-24 00:35:01 [INFO]  - Running function: get_dev_variables
2024-05-24 00:35:01 [INFO]  - Separate boot partition detected
2024-05-24 00:35:01 [DEBUG] - LOCAL_DEV_BOOT_PATH=/dev/mmcblk0p1 | LOCAL_DEV_ROOT_PATH=/dev/mmcblk0p2
2024-05-24 00:35:01 [DEBUG] - LOCAL_ROOT_PARTN=
2024-05-24 00:35:01 [INFO]  - Calculating size for dd to cover bootsector in blocks (512B block size) and adding 256 blocks to overlap into root (only used in img creation)
2024-05-24 00:35:01 [DEBUG] - Running: fdisk -lo start /dev/mmcblk0 | tail -1
2024-05-24 00:35:01 [DEBUG] - LOCAL_ROOT_START= Blocks | LOCAL_BOOTSECTOR=-1 Blocks | LOCAL_DDBOOTSECTOR=255 Blocks
2024-05-24 00:35:01 [DEBUG] - LOCAL_ROOT_START=0 Bytes | LOCAL_BOOTSECTOR=-512 Bytes
2024-05-24 00:35:01 [DEBUG] - LOCAL_RESIZE2FS_MIN=0 Bytes
2024-05-24 00:35:01 [INFO]  - Setting TOTAL (space needed for files on root) to size calculated by resize2fs
2024-05-24 00:35:01 [DEBUG] - TOTAL=0 Bytes
2024-05-24 00:35:01 [INFO]  - Calculating .img file size by adding LOCAL_BOOTSECTOR to TOTAL (only used in img creation)
2024-05-24 00:35:01 [DEBUG] - TRUNCATE_TOTAL=-512 Bytes
2024-05-24 00:35:01 [INFO]  - Running function: get_shared_variables
2024-05-24 00:35:01 [DEBUG] - LOOP=
2024-05-24 00:35:01 [INFO]  - Separate boot partition detected
2024-05-24 00:35:01 [DEBUG] - Running: cat /etc/fstab | grep '/boot' | awk '{print $2}'
2024-05-24 00:35:01 [DEBUG] - BOOT_PATH=/boot | IMG_DEV_BOOT_PATH=p1 | IMG_DEV_ROOT_PATH=p2
2024-05-24 00:35:01 [INFO]  - -y selected by user. prompts are disabled
2024-05-24 00:35:07 [INFO]  - 6 seconds passed, user did not stop operation
------------------------------------------------------------------------------
2024-05-24 00:35:07 [WARNING] - Removing: /backup/RPI.img
2024-05-24 00:35:09 [INFO]  - Using dd to create bootsector
------------------------------------------------------------------------------
2024-05-24 00:35:09 [ERROR] - DD TO LOCAL_BOOTSECTOR FAILED:
255+0 records in
255+0 records out
130560 bytes (131 kB, 128 KiB) copied, 0.00577474 s, 22.6 MB/s
------------------------------------------------------------------------------
2024-05-24 00:35:09 [ERROR] - Cleanup function called with non zero exit code: exit 1
2024-05-24 00:35:09 [INFO]  - Elapsed time: 00.08
2024-05-24 00:35:09 [DEBUG] - Exiting script

Could not stat device /dev/mmcblk0 on a CM4

I just wanted to evaluate your script and tried to create a backup and immediately got following error message:

## Zoom speed NOT requested...
## Scanning filesystem and calculating...
Error: Could not stat device /dev/mmcblk0
/dev/mmcblk0boot0
/dev/mmcblk0boot1 - No such file or directory.

!! Script stopped by user...
## Exiting and cleaning up...
## Please stand by...
## Done.
## Elapsed time: 00.10

The script just hangs and I had to cancel the script. It also doesn't produce any log file I can provide for further analysis of the issue.

It's a cm4 with following partitions:

pi@raspberrypi:~ $ lsblk
NAME         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
mmcblk0      179:0    0  29.1G  0 disk 
├─mmcblk0p1  179:1    0   512M  0 part /boot/firmware
└─mmcblk0p2  179:2    0  14.8G  0 part /
mmcblk0boot0 179:32   0     4M  1 disk 
mmcblk0boot1 179:64   0     4M  1 disk 
nvme0n1      259:0    0 119.2G  0 disk 
├─nvme0n1p1  259:1    0   512M  0 part 
└─nvme0n1p2  259:2    0 118.7G  0 part 

Run shrink-backup stops with error when running within Webmin

Hi

First of all I appretiate your script very much. It's working like a charm and easy to handle.

From SSH (XShell) shrink-backup does work totally fine, high speed, from SD card to a /mnt mounted network drive.
I use the script like click and go with the -y feature.

Now, on a Raspberry I like to use Debian Lite (without desktop) but together with Webmin web UI for some system maintenance.
Within Webmin I e.g. can configure some user commands to be started on button click.

Configuring the same command as Webmin user command shrink-backup fails with error 256 / last error: DD TO LOCAL_BOOTSECTOR FAILED. Although, ~512MB will be written...

I don't think this is the real ERROR because from XShell all works fine.
Also, there is another error output some lines before which doesn't appear in XShell console: tee: /dev/tty: No such device or address.

So, here my question:
Does shrink-backup need /dev/tty for IO and probably in the Webmin web fake console it is missing ?
If I try tty in Webmin it also says not a tty.
Unfortunately tty cannot be redirected so easily to e.g. stdout to make output visible in Webmin.
By mount --bind /dev/null /dev/tty? it just can be nulled...

Within shrink-backup script I see some tee /dev/tty in if clauses where some shrink/backup fault should be catched. In my case it seems that also a missing tty is being catched ?
Would you think you could improve shrink-backup to run in non console environment ?

Output from cd /home/pi/shrinkBackup ; sudo ./shrink-backup -a -y /mnt/dsRaspberryBackup/pi/fhem-pi-2-$(date +"%Y%m%d%H%M%S").img ..

dumpe2fs 1.47.0 (5-Feb-2023)
resize2fs 1.47.0 (5-Feb-2023)
##############################################################################
# DISABLE PROMPTS SELECTED (-y), NO WARNINGS ABOUT DELETION!!!
# A backup will be created at /mnt/dsRaspberryBackup/pi/fhem-pi-2-20240608131404.img
# ----------------------------------------------------------------------------
# Write to logfile: false
# Resize2fs decide size: true
# Autoexpand filesystem at boot: true
# Use exclude.txt: false
# Bootsector size: 515MB
# Estemated root usage: 5917MB
# Resize2fs decide minimum (root partition): 7351MB
# Total img size: 7867MB
# PRESS CTRL+C WITHIN 5s TO CANCEL!
##############################################################################
## Creating bootsector...
tee: /dev/tty: No such device or address

45013504 bytes (45 MB, 43 MiB) copied, 1 s, 45.0 MB/s
90249728 bytes (90 MB, 86 MiB) copied, 2 s, 45.1 MB/s
135683584 bytes (136 MB, 129 MiB) copied, 3 s, 45.2 MB/s
181313536 bytes (181 MB, 173 MiB) copied, 4 s, 45.3 MB/s
227771392 bytes (228 MB, 217 MiB) copied, 5 s, 45.6 MB/s
274211328 bytes (274 MB, 262 MiB) copied, 6 s, 45.7 MB/s
320479744 bytes (320 MB, 306 MiB) copied, 7 s, 45.8 MB/s
366617088 bytes (367 MB, 350 MiB) copied, 8 s, 45.8 MB/s
407773696 bytes (408 MB, 389 MiB) copied, 9 s, 45.3 MB/s
454144512 bytes (454 MB, 433 MiB) copied, 10 s, 45.4 MB/s
500572672 bytes (501 MB, 477 MiB) copied, 11 s, 45.5 MB/s
1057023+0 records in
1057023+0 records out
541195776 bytes (541 MB, 516 MiB) copied, 44.9402 s, 12.0 MB/s
## DD TO LOCAL_BOOTSECTOR FAILED!!!
## Cleanup function called with non zero exit code, something went wrong!!!
## Exiting and cleaning up...
## Please stand by...
## Done.
## Elapsed time: 00.53

Command failed with exit status 256

Best regards

Bug in shrink-backup (!! PARTED FAILED!!!)

Hi, thank you for this amazing tool. I've encountered an error:

## Creating bootsector...

18431+0 records in
18431+0 records out
9436672 bytes (9,4 MB, 9,0 MiB) copied, 0,439452 s, 21,5 MB/s
## Resizing img file...
## Looping img file...
## Removing root partition...
## Recreating root partition...
Error: The location 4194304 is outside of the device /dev/loop0.
!! PARTED FAILED!!!
!! Cleanup function called with non zero exit code, something went wrong!!!
## Exiting and cleaning up...
## Please stand by...
## Done.

shrink-backup.log

shrink-backup with 'f2fs'?

Hello,

My RaspberryPi runs since years under "f2fs" (Flash-Friendly File System).
It seems your scripts relys on btrfs?

Is there a change to work with f2fs?
I see so many btrfs command in the scripts doing not know the exact function...

2024-04-17 22:09:43 [DEBUG] - Running: mkfs.btrfs -m single -L  -f -v /dev/loop0p2
./shrink-backup: Zeile 1162: mkfs.btrfs: Kommando nicht gefunden.
------------------------------------------------------------------------------
2024-04-17 22:09:43 [INFO]  - Creating temp directory
2024-04-17 22:09:43 [DEBUG] - Running: mktemp -d -t backup-XXX
2024-04-17 22:09:43 [DEBUG] - TMP_DIR=/tmp/backup-rMk
2024-04-17 22:09:43 [INFO]  - Creating btrfs subvolumes
2024-04-17 22:09:43 [DEBUG] - Running: mount -o compress=zstd /dev/loop0p2 /tmp/backup-rMk
------------------------------------------------------------------------------
2024-04-17 22:09:44 [ERROR] - ROOT MOUNT FAILED:
mount: /tmp/backup-rMk: wrong fs type, bad option, bad superblock on /dev/loop0p2, missing codepage or helper program, or other error.
------------------------------------------------------------------------------

LOOP paths can not be set // umounting of /boot/firmware

Hello,

What I did:
Downloaded latest version (1.1) of shrink-backup.
The shring-backup-folder is located on my NAS mounted unter /mnt/netbackup/.

-rw-r--r-- 1 1024 users 9377861120 Jun  4 22:31 backup_george_bookworm.img
-rw-r--r-- 1 1024 users         83 Aug  1  2023 exclude.txt
-rw-r--r-- 1 1024 users       1539 Jun 25 17:20 LICENSE
-rw-r--r-- 1 1024 users      18192 Jun 25 17:00 README.md
-rwxr-xr-x 1 1024 users      99071 Jun 25 16:58 shrink-backup
-rw-r--r-- 1 1024 users      91117 Jul 20 23:06 shrink-backup.log

Ok, so I started upadte -U the above visible *.img file
sudo /mnt/netbackup/shrink-backup/shrink-backup -Uz /mnt/netbackup/shrink-backup/backup_george_bookworm.img
So far so good, output of program:

## Zoom speed requested...
## Scanning filesystem and calculating...
## Looping img file...
#####################################################################################
# Updating /mnt/netbackup/shrink-backup/backup_george_bookworm.img                  #
# f2fs filesystem detected on root                                                  #
# Autoexpand filesystem at boot not available for f2fs                               #
# Resize operations not available for f2fs                                          #
# --------------------------------------------------------------------------------- #
# Write to logfile: false                                                           #
# Zoom speed requested: true                                                        #
# Autocalculate img root partition size: false                                      #
# Autoexpand filesystem at boot: false                                              #
# Use exclude.txt: false                                                            #
# Bootsector size: 515MiB                                                           #
# Estemated root usage: 10661MiB                                                    #
# Total img size: 8943MiB                                                           #
#####################################################################################
## Do you want to continue? [y/n] n
!! Aborting...
## Exiting and cleaning up...
## Please stand by...
## Done.
## Elapsed time: 00.20

Since I discovered logfile was disables I stopped script by entering n.
So I restarted backup with additional l option:
sudo /mnt/netbackup/shrink-backup/shrink-backup -Ulz /mnt/netbackup/shrink-backup/backup_george_bookworm.img
But since than the script shows errors....

## Debugging requested, writing to log file: /mnt/netbackup/shrink-backup/shrink-backup.log
## Zoom speed requested...
## Scanning filesystem and calculating...
lsblk: : not a block device
## Looping img file...
!! LOOP paths can not be set, retrying in 5 seconds...
!! LOOP paths can not be set, retrying in 5 seconds...
!! LOOP paths can not be set, retrying in 5 seconds...
^C
!! Script stopped by user...
## Exiting and cleaning up...
## Please stand by...
## Done.
## Elapsed time: 00.21

And this repeat everytime I restart the script.
Logfile:
shring-backup.log

losetup --list
Gives no output.

Output of lsblk:

 $ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
mmcblk0     179:0    0 119.1G  0 disk
├─mmcblk0p1 179:1    0   512M  0 part
└─mmcblk0p2 179:2    0 118.6G  0 part /

This is the effect we have seen in some older issues:
The mmcblk0p1 was un-mount for what ever reason.
Re-mounting it again to /boot/firmware makes the script run as it should.

Since you search in /proc/mounts on your script I was wondering if this unmount-behaviour may be influenced by the order of mounts.

So I rebooted, started shrink-backup again and stopped with no (not continue).
The first time nothing happened (checked with lsblk).
Starting shrink-backup again and stopping with no (not continue) then brought the result with the unmounting of the /boot/firmware partition!

Remounting /boot/firmware and starting / stopping the script several times then never umounts /boot/firmware.

Repeating with reboot, mount /mnt/netbackup starting backup uns stopping ist with entering no this time immediately leads to an unmounted /boot/firmware ....
Re-mount /boot/firmware manually and starting / stopping the script several times then never umounts anything.

Strange behavior... not able to grab the root cause.

Script fails if Snap is installed

Describe the bug
The script simply assumes /dev/loop0 is unused, which is not always the case, particularly on systems where snap packages are installed.

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0         7:0    0  93.3M  1 loop /snap/core/16204
loop2         7:2    0  59.7M  1 loop /snap/core20/2107
loop3         7:3    0  43.2M  1 loop /snap/certbot/3567
sda           8:0    0 447.1G  0 disk 
└─sda1        8:1    0 447.1G  0 part /mnt/ssd
mmcblk0     179:0    0 119.1G  0 disk 
├─mmcblk0p1 179:1    0   512M  0 part /boot/firmware
└─mmcblk0p2 179:2    0 118.6G  0 part /

Changing the LOOP variable to something like /dev/loop999 along with setting IMG_DEV_BOOT_PATH, IMG_DEV_ROOT_PATH and cleanup parameters accordingly does fix the problem for me, but perhaps you'd like to implement a more elegant solution.

Harware (please complete the following information):

  • OS: RaspberryPiOS/Debian
  • Version: 12 aarch64

Additional context
shrink-backup.log

Bug in shrink-backup

Hello!

We are running into an issue of some of our devices with a no space left on the device.

562.33M 6% 17.66MB/s 0:07:31 rsync: [receiver] write failed on "/tmp/backup-Qzjbebgh3H/var/log/lightdm/lightdm.log": No space left on device (28)

If I run a df command on the device I see a ton of free space.

/dev/root 30340960 7986796 21062172 28% /
devtmpfs 1678472 0 1678472 0% /dev
tmpfs 1942696 0 1942696 0% /dev/shm
tmpfs 777080 1072 776008 1% /run
tmpfs 5120 4 5116 1% /run/lock
/dev/mmcblk0p1 261108 32458 228650 13% /boot
tmpfs 388536 16 388520 1% /run/user/1000
/dev/loop0p2 7326828 8 6933232 1% /tmp/backup-Tg7jtvayTS

Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.