System backups

25/11/2021

In this blog I'll explore some solutions used to backup the entire system, trying to achive this goal in the most eficient way possible.

Constraints

Becouse I want a solution that is more of a general backup, these are the requirements for the ideal soution:

Raw copy

The naive aproch, I call it so because despite of beeing one of the easyest solution it has some disadvantages like:

Backup of each partition

This is a slightly more advanced approach because comes with the following advantages: The steps used to make this kind of backup where the following:

#archive command for ext4 partition
        sudo fsarchiver savefs /mnt/kesu/backup_ubuntu/ubuntu_ext4rootfs.fsa /dev/nvme0n1p2 -v -j4
#exclude some dirs/files
	#	--exclude
#restore command for ext4 partition
        sudo fsarchiver restfs /mnt/kesu/backup_ubuntu/ubuntu_ext4rootfs.fsa id=0,dest=/dev/nvme0n1p2 -v -j4
#backup/restore esp partition
	sudo dd if=/dev/nvme0n1p1 of=/mnt/kesu/backup_ubuntu/esp_boot status=progress

	sudo dd of=/dev/nvme0n1p1 if=/mnt/kesu/backup_ubuntu/esp_boot status=progress
#backup GPT partition table
	sudo sgdisk --backup=/mnt/kesu/backup_ubuntu/gpt_part_table.backup /dev/nvme0n1
#restore GPT partition table
	sgdisk --load-backup=/mnt/kesu/backup_ubuntu/gpt_part_table.backup /dev/nvme0n1
				

More details about how to install and run fsarchiver can be found on their website. Nonetheless don't forgoet to edit the NVRAM Variables to point to your secondary bootloader located on the ESP partition, to do that you can use tools like efibootmgr or UEFI shell.

Footnotes

  1. as long as the used space of the backedud drive si <= the size of the drive used for restore