Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7403

Advanced users • shrink-backup v1.3 released

$
0
0
Old thread locked but can be read here: viewtopic.php?p=2261596
Github: https://github.com/UnconnectedBedna/shrink-backup

Release notes:
  • New options:
    • -q|--quiet mode. Mute rsync output
    • --no-color mode. No colorization in script
    • --rsync. User will get presented with the rsync line that will be ran and can modify it
    • --chroot option to access an image in a chroot environment (systemd-nspawn) to for example update/install packages or rebuild initramfs. Only works from the system you created the img
  • Autoexpansion for operating systems:
    • Kali-arm
    • Ubuntu-server-arm (Ubuntu autoexpands by default, but that can be disabled with -e option)
  • UI tweaks
  • Removed check for .img extension while using --loop so it works on other img formats (for example .iso)
  • Changed the dd line to use conv=fsync instead of sync and added a sync operation after dd is done to try to mitigate the "can not set loop paths" problem that some users experience
  • User confirmation now require to also press enter after y/n
  • Added /snap/* in exclude.txt and to be excluded as default if not using the exclude file
  • Implemented a lock file that makes it impossible for boot partition to become unmounted during shrink-backup
  • Nested btrfs subvolumes can now be added & removed in an update (-U)
  • New way of excluding subvolumes for btrfs (exclude_btrfs.txt or shrink-backup_btrfs.conf depending on how you installed, see README for information)
  • --fix now also adds option --fsync to rsync
If you have made changes to exclude.txt and you used git to install, git pull will fail due to conflicts.
The easiest way to resolve this is to make notes of the paths you added, then:

Code:

git reset --hardgit pull
Then add your edited paths back into exclude.txt at the end of the file again.


Short description:

I made this script because I wanted a universal method of backing up my SBC:s into small img files as fast as possible (with rsync), indepentent of what os is in use.

shrink-backup is a very fast utility for backing up your SBC:s into minimal bootable img files for easy restore with autoexpansion at boot.

Can backup any device with or without a boot partition as long as the filesystem is ext4, f2fs or btrfs (with subvolumes).

Supports backing up root & boot (if existing) partitions. Data from other partitions will be written to root if not excluded.
For btrfs, all existing top level 5 subvolumes in /etc/fstab will be created with new backups, nested subvolumes will be created and can also be removed/added in an update of the backup img.

Autoexpansion tested & supported on following operating systems:
  • Raspberry Pi OS (bookworm and older)
  • Armbian
  • Manjaro-arm
  • DietPi
  • ArchLinuxArm
  • Kali-arm
  • Ubuntu-server-arm (Ubuntu autoexpands by default, but that can be disabled with -e option)
Autoexpansion does not work on f2fs due to filesystem limitations.
Other operating systems will most likely work too, but autoexpansion will not.
The script will report the operating system as "unknown" but that does not mean the script will fail.
Feel free to make a feature request if you use an operating system not on this list.

Full functionality for usage inside webmin (including "custom command" button).

Latest release: shrink-backup.v1.3
Testing branch: If you want to use the absolute latest version. There might be bugs.

Very fast restore thanks to minimal size of img file.

Default device that will be backed up is determined by scanning what disk-device root resides on.
This means that if boot is a partition, that partition must be on the same device and before the root partition.
The script considers everything on the device before root as the bootsector.

Backing up/restoring, to/from: usb-stick /dev/sdX with Raspberry pi os has been tested and works. Ie, writing an sd-card img to a usb-stick and vice versa works.

Ultra-fast incremental backups to existing img files.

See wiki for information about installation methods, usage and examples.
Ideas and feedback is always appreciated, whether it's positive or negative. Please just keep it civil. :)
If you find a bug or think something is missing in the script, please file a bug report or feature request

To restore a backup, simply "burn" the img file to a device using your favorite method.

Usage:

Code:

shrink-backup -hScript for creating an .img file and subsequently keeing it updated (-U), autoexpansion is enabled by defaultDirectory where .img file is created is automatically excluded in backup########################################################################Usage: sudo shrink-backup [options] imagefile.img [extra space (MiB)]  -U              Update existing img file (rsync to existing img)                    Optional [extra space] extends img root partition  -a              Autocalculate root size partition, [extra space] is ignored.                    When used in combination with -U:                    Expand if partition is >=256MiB smaller than autocalculated recommended minimum                    Shrink if partition is >=512MiB bigger than autocalculated recommended minimum  -t              Use exclude.txt in same folder as script to set excluded directories                    One directory per line: "/dir" or "/dir/*" to only exclude contents  -y              Disable prompts in script (please use this option with care!)  -e              Disable autoexpansion on root filesystem when image is booted  -l              Write debug messages to logfile shrink-backup.log located in same directory as script  -z              Make script zoom at light-speed, only question prompts might slow it down                    Can be combined with -y for UNSAFE ultra-mega-superduper-speed  -q --quiet      Do not print rsync copy process  --no-color      Run script without color formatted text  --fix           Try to fix the img file if -a fails with a "broken pipe" error                    Will activate rsync options --delete-before & --fsync  --rsync         Define custom rsync line manually. Will print rsync line for user to edit  --loop [img]    Loop img file and exit, works in combination with -l & -z                    If optional [extra space] is defined, the img file will be extended with the amount before looping                    NOTE that only the file gets truncated, no partitions                    Useful if you for example want to manually manage the partitions  --chroot [img]  Use systemd-nspawn. Loop img file, mount to temp directory, enter chroot environment and drop to shell                    This will let you make changes in a chroot environment directly on the img file                    For example update with package manager or rebuild initramfs                    The script will keep running in the background                    Type 'exit' when done. Script will unmount, remove temp directory/loop and exit  --f2fs          Convert root filesystem on img from ext4 to f2fs                    Only works on new img file, not in combination with -U                    Will make backups of fstab & cmdline.txt to: fstab.shrink-backup.bak & cmdline.txt.shrink-backup.bak                    Then change ext4 to f2fs in both files and add discard to options on root partition in fstab  --version      Print version and exit  -h --help      Show this help snippet########################################################################Examples:sudo shrink-backup -a /path/to/backup.img (create img, resize2fs calcualtes size)sudo shrink-backup -e -y /path/to/backup.img 1024 (create img, ignore prompts, do not autoexpand, add 1024MiB extra space)sudo shrink-backup -Utl /path/to/backup.img (update img backup, use exclude.txt and write log to shrink-backup.log)sudo shrink-backup -U /path/to/backup.img 1024 (update img backup, expand img size/root partition with 1024MiB)sudo shrink-backup -Ua /path/to/backup.img (update img backup, resize2fs calculates and resizes img file if needed)sudo shrink-backup -Ua --fix /path/to/backup.img 1024 (update img backup, automatically resizes img file if needed, fix img free space)sudo shrink-backup -l --loop /path/to/backup.img 1024 (write to log file, expand IMG FILE (not partition) by 1024MiB and loop)

Statistics: Posted by bedna — Sat Aug 02, 2025 1:09 pm — Replies 0 — Views 23



Viewing all articles
Browse latest Browse all 7403

Trending Articles