Full system backup with SquashFS
Jump to navigation
Jump to search
Contents
Overview
SquashFS [1] makes highly compressed read-only backup archives of complete systems. It is convenient since you can mount it and find/grep/cp/tree in it without decompressing the whole SquashFS archive. Backup takes less time and overhead of file retrieval/traversal is lower compared to tar, but modifying an existing archive is impossible as a penalty.
Prepare live CD/DVD/USB
You should have squashfs-tools installed in live CD/DVD/USB to make SquashFS archives. Please refer to Archiso#Configure the live medium on how to configure packages.x86_64
and build live CD/DVD/USB with squashfs-tools installed.
Backup in live environment
Boot into live CD/DVD/USB and mount filesystems you would like to backup.
Note: The following example is for an EFI-grub Arch installation with sdb1 as EFI partition and sdb2 as root partition.
# fsck /dev/sdb2 # fsck /dev/sdb1 # mount /dev/sdb2 /mnt # mount /dev/sdb1 /mnt/boot/efi # /somewhere/mksquashfs.sh SOURCE_DIRECTORY BACKUP_ARCHIVE_DIRECTORY
where
/somewhere/mksquashfs.sh
#!/usr/bin/env bash # Sanity if [ $# -ne 2 ]; then echo "invoke: mksquashfs.sh SOURCE_DIRECTORY BACKUP_ARCHIVE_DIRECTORY" exit 1 fi echo -ne "\n\nHave you fsck'd? " read # Backup mksquashfs \ "$1" "$2/$(date +%Y%m%d_%a).sfs" \ -comp gzip \ -xattrs \ -progress \ -mem 5G \ -wildcards \ -e \ boot/efi \ boot/grub \ boot/initramfs-linux"*".img
Restore (decompress)
Warning: The following is complete but not yet tested. Do not use before this warning sign is removed.
#!/bin/bash # Path to extract files target=/mnt # Path to backup SquashFS archive file archive=/somewhere/backup.sfs unsquashfs -stat $archive unsquashfs -force -dest $target $archive
Note: To make system bootable after restore, you should:
- Fix fstab
- arch-chroot
- mkinitcpio -p linux
- grub-install
- grub-mkconfig
Restore (mount and copy)
Warning: The following is complete but not yet tested. Do not use before this warning sign is removed.
- mount somewhere/backup.sfs /mnt
- cp /mnt/somefile /somewhere/damaged-somefile