diff --git a/README.md b/README.md index d6a8296..454c047 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ The only user intervention is to boot the target computer into Clonezilla bootab - Automatically start Custom backup option -- Inspect local partitions looking for `backup.conf` configuration file in the root folder +- Inspect local partitions looking for `clonezilla-autobackup.conf` configuration file in the root folder -- Compare hardware ID of the target hardware to the hardware ID in the `backup.conf` (correct backup configuration check) +- Compare hardware ID of the target hardware to the hardware ID in the `clonezilla-autobackup.conf` (correct backup configuration check) - Determine backup target partition (backup folder is created in the root folder on that partition) @@ -37,7 +37,7 @@ The only user intervention is to boot the target computer into Clonezilla bootab ### Outcome -The resulting backup is created in a folder (folder name is supplied in the `backup.conf` file) on the backup partition (partition is supplied in the `backup.conf` file). Backup parameters are also supplied in the `backup.conf` file. Those are passed to Clonezilla engine at runtime. +The resulting backup is created in a folder (folder name is supplied in the `clonezilla-autobackup.conf` file) on the backup partition (partition is supplied in the `clonezilla-autobackup.conf` file). Backup parameters are also supplied in the `clonezilla-autobackup.conf` file. Those are passed to Clonezilla engine at runtime. ## Bill of Materials @@ -95,76 +95,87 @@ Relevant fdisk output for this disk is: 1. Set timeout to 5 seconds (default is 30): - set timeout = "5" + set timeout = "5" - 2. Location this line (usually the first Clonezilla menu item): + 2. Locate this line (usually the first Clonezilla menu item): - menuentry --hotkey=r "Clonezilla live (VGA 800x600 & To RAM)" --id live-toram { + menuentry --hotkey=r "Clonezilla live (VGA 800x600 & To RAM)" --id live-toram { 3. Copy the entire `menuentry` block ahead of the first menublock - the default menu item is 0 (first on the list) - menuentry --hotkey=r "Clonezilla live (VGA 800x600 & To RAM)" --id live-toram { - search --set -f /live/vmlinuz - $linux_cmd /live/vmlinuz boot=live union=overlay username=user hostname=noble config quiet loglevel=0 noswap edd=on nomodeset enforcing=0 noeject locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=788 toram=live,syslinux,EFI,boot,.disk,utils net.ifnames=0 splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 - $initrd_cmd /live/initrd.img - } +`` + menuentry --hotkey=r "Clonezilla live (VGA 800x600 & To RAM)" --id live-toram { + search --set -f /live/vmlinuz + $linux_cmd /live/vmlinuz boot=live union=overlay username=user hostname=noble config quiet loglevel=0 noswap edd=on nomodeset enforcing=0 noeject locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=788 toram=live,syslinux,EFI,boot,.disk,utils net.ifnames=0 splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 + $initrd_cmd /live/initrd.img + } +`` - 4. In the new block, modify the menuitem description and the boot command according to the following: - menuentry --hotkey=r "Clonezilla Autobackup (VGA 800x600 & To RAM)" --id live-autobackup { - search --set -f /live/vmlinuz - $linux_cmd /live/vmlinuz boot=live union=overlay username=user hostname=noble config quiet loglevel=0 noswap edd=on nomodeset enforcing=0 noeject locales=locales=en_EN.UTF-8 keyboard-layouts=NONE ocs_live_run="/lib/live/mount/medium/live/custom-ocs" ocs_live_extra_param="" ocs_live_batch="no" vga=788 toram=live,syslinux,EFI,boot,.disk,utils net.ifnames=0 splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 - $initrd_cmd /live/initrd.img - } + 4. In the new block, modify the menuitem description and the boot command according to the following: +`` + menuentry --hotkey=r "Clonezilla Autobackup (VGA 800x600 & To RAM)" --id live-autobackup { + search --set -f /live/vmlinuz + $linux_cmd /live/vmlinuz boot=live union=overlay username=user hostname=noble config quiet loglevel=0 noswap edd=on nomodeset enforcing=0 noeject locales=en_EN.UTF-8 keyboard-layouts=NONE ocs_live_run="/run/live/medium/live/custom-ocs" ocs_live_extra_param="" ocs_live_batch="no" vga=788 toram=live,syslinux,EFI,boot,.disk,utils net.ifnames=0 splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 + $initrd_cmd /live/initrd.img + } +`` + ... which is essentially this overwritten partials: + `--id live-autobackup` + `locales=en_EN.UTF-8 keyboard-layouts=NONE ocs_live_run="/run/live/medium/live/custom-ocs"` + 5. Save `grub.cfg` file The autobackup setup of Clonezilla is now complete. ### Prepare target computer -#### Backup configuration file -Backup configuration file tells automatic Clonezilla what kind of backup needs to be performed. +#### clonezilla-autobackup.conf configuration file +clonezilla-autobackup.conf configuration file tells automatic Clonezilla what kind of backup needs to be performed. It should be localed in the root folder on one of the drives of the target computer: - /backup.conf + /clonezilla-autobackup.conf A sample backup file is below: + +``` +# This is a comment, and is ignored +4c4c4544-0054-3610-804a-c7c04f444b33 +7B0DFCE74B228860 +-q2 -j2 -nogui -z1p -i 2000000 -p poweroff savedisk xps15dev_system +D2DE19FADE19D815 +``` - 4c4c4544-0054-3610-804a-c7c04f444b33 - 7B0DFCE74B228860 - -q2 -j2 -nogui -z1p -i 2000000 -p poweroff savedisk xps15dev_system - D2DE19FADE19D815 - Let's review it line by line ##### Line 1 - hardware ID of the target machine: - 00020003-0004-0005-0006-000700080009 + 00020003-0004-0005-0006-000700080009 This ID could be looked up with this command: `sudo lshw -quiet -class system | grep configuration | grep uuid` +(Alternative command: `sudo cat /sys/class/dmi/id/product_uuid`) - $ sudo lshw -quiet -class system | grep configuration | grep uuid - configuration: boot=normal chassis=desktop family=Default string sku=Default string uuid=00020003-0004-0005-0006-000700080009 + $ sudo lshw -quiet -class system | grep configuration | grep uuid + configuration: boot=normal chassis=desktop family=Default string sku=Default string uuid=00020003-0004-0005-0006-000700080009 -The easiest way to build `backup.conf` file is to boot into interactive Clonezilla, drop into shell instead of starting the backup and look it up there. +The easiest way to build `clonezilla-autobackup.conf` file is to boot into interactive Clonezilla, drop into shell instead of starting the backup and look it up there. Clonezilla checks if correct configuration file has been found and ignores the ones with unmatched hardware IDs ##### Line 2 - UUID of the partition to store back up file on - 7B0DFCE74B228860 + 7B0DFCE74B228860 If the target computer has mulitple disk drives, you can specify on of the partitions on the drives that are not part of the backup. Typically this is the partition UUID of the DATA partition of the 2TB backup drive we are building. Note that `7B0DFCE74B228860` is UUID of an exFAT partition (windows). Linux ext4 partition UUID will look like `38d9e8cd-deda-4735-ad97-a795665e77fe` -You can look up partition UUIDs using `sudo blkid` command. - +You can look up partition UUIDs using `sudo blkid` command (Alternative command: `lsblk -f`). ##### Line 3 - Clonezilla command line arguments - -q2 -j2 -nogui -z1p -i 2000000 -p poweroff savedisk xps15dev_system + -q2 -j2 -nogui -z1p -i 2000000 -p poweroff savedisk xps15dev_system One by one: @@ -177,12 +188,12 @@ One by one: - `savedisk` is command to backup the entire drive (`saveparts` saves individual partitions). - `xps15dev_system` is the name of the target folder for the backup. -The esiest way to build this line is to run an interactive Clonezilla session, select all desired parameters and save the resulting command line. +The easiest way to build this line is to run an interactive Clonezilla session, select all desired parameters and save the resulting command line. There is also a command line reference here: [Man page of ocs-sr](https://clonezilla.org/fine-print-live-doc.php?path=./clonezilla-live/doc/98_ocs_related_command_manpages/01-ocs-sr.doc#google_vignette) ##### Line 4, 5, 6 and so on - D2DE19FADE19D815 + D2DE19FADE19D815 Lines 4 onward list UUID of partitions being backed up. If you are using `savedisk` command - any partion on a disk will make Clonezilla backup the entire disk. diff --git a/clonezilla/live/custom-ocs b/clonezilla/live/custom-ocs index a5fa12e..533bf79 100644 --- a/clonezilla/live/custom-ocs +++ b/clonezilla/live/custom-ocs @@ -1,10 +1,9 @@ #!/usr/bin/perl -# Find and read the backup configuration file my $TRUE = (1==1); my $FALSE = !$TRUE; -my $configFile = "/home/config/backup.conf"; +my $configFile = "/home/config/clonezilla-autobackup.conf"; my $backupFolder = "/home/partimag"; my $failed = $FALSE; my $failedMsg = ""; @@ -17,117 +16,123 @@ my $backupDisk; printf "Clonezilla backup by local backup configuration file\n"; printf "====================================================\n"; -printf "Inspecting hardware configration... "; +printf "Inspecting hardware configuration... "; @uuids = `sudo blkid`; my $hw = `sudo lshw -quiet -class system | grep configuration | grep uuid`; $hw =~ /uuid=([0-9|a-f]{8}-[0-9|a-f]{4}-[0-9|a-f]{4}-[0-9|a-f]{4}-[0-9|a-f]{12})/i; my $machine = $1; printf "done\nHardware uuid=$machine\n"; -system("sudo mkdir /home/config >> /dev/null 2>&1"); +system("sudo mkdir /home/config > /dev/null 2>&1"); +# Find and read the backup configuration file foreach $uuid (@uuids) { - $uuid =~ /^(\/dev\/.+):/i; - $disk = $1; - printf "Inspecting partition: $disk..."; - system("sudo umount /home/config >> /dev/null 2>&1"); - system("sudo umount $disk >> /dev/null 2>&1"); - if (system("sudo mount $disk /home/config >> /dev/null 2>&1") == 0) { - if (-e $configFile ) { - printf " found backup configration file\n"; - unless ( open(FILE, "<", $configFile) ) { - printf "Error opening backup configration file: $!\n"; - } else { - @config = ; - close FILE; - - chomp $config[0]; - $backupDisk = $config[0]; - if ($backupDisk =~ /^$machine/i || $uuid =~ /$backupDisk/i) { - printf "Backup uuid matches this hardware or disk: $backupDisk\n"; - system("sudo umount /home/config >> /dev/null 2>&1"); - $found = $TRUE; - last; - } - else { - printf "Backup uuid=$backupDisk\nDoes not match that of this hardware..."; - } - } + $uuid =~ /^(\/dev\/.+):/i; + $disk = $1; + printf "Inspecting partition: $disk..."; + system("sudo umount /home/config > /dev/null 2>&1"); + system("sudo umount $disk > /dev/null 2>&1"); + if (system("sudo mount $disk /home/config > /dev/null 2>&1") == 0) { + if (-e $configFile ) { + printf " found backup configuration file\n"; + unless ( open(FILE, "<", $configFile) ) { + printf "Error opening backup configuration file: $!\n"; + } else { + @config = ; + close FILE; + + # Remove all comments starting with # + @config = grep { !/^#/ } @config; + + # Remove all blank lines + @config = grep { /\S/ } @config; + + # Remove all trailing newlines + chomp @config; + + $backupDisk = $config[0]; + if ($backupDisk =~ /^$machine/i || $uuid =~ /$backupDisk/i) { + printf "Backup uuid matches this hardware or disk: $backupDisk\n"; + system("sudo umount /home/config > /dev/null 2>&1"); + $found = $TRUE; + last; + } + else { + printf "Backup uuid=$backupDisk\ndoes not match that of this hardware..."; } + } } - print " skipped.\n"; + } + print " skipped.\n"; } if ($found) { - if (-d $backupFolder) { - $tmp = `mount | grep $backupFolder`; - if ($tmp =~ $backupFolder) { - system("sudo umount $backupFolder >> /dev/null 2>&1"); - } - } else { - system("sudo mkdir $backupFolder >> /dev/null 2>&1"); + if (-d $backupFolder) { + $tmp = `mount | grep $backupFolder`; + if ($tmp =~ $backupFolder) { + system("sudo umount $backupFolder > /dev/null 2>&1"); } - chomp $config[1]; - if (system("sudo mount -U $config[1] $backupFolder") == 0) { - printf "Mounted $backupFolder: "; - printf `sudo mount | grep $backupFolder`; - chomp $config[2]; - my $params = $config[2]; - if ($params =~ "savedisk") { - $saveDisk = $TRUE; - } elsif ($params =~ "saveparts") { - $saveDisk = $FALSE; - } else { - $failed = $TRUE; - $failedMsg = "Unable to determine type of backup: disk or partition"; - } + } else { + system("sudo mkdir $backupFolder > /dev/null 2>&1"); + } + if (system("sudo mount -U $config[1] $backupFolder") == 0) { + printf "Mounted $backupFolder: "; + printf `sudo mount | grep $backupFolder`; + my $params = $config[2]; + if ($params =~ "savedisk") { + $saveDisk = $TRUE; + } elsif ($params =~ "saveparts") { + $saveDisk = $FALSE; } else { - $failed = $TRUE; - $failedMsg = "Unable to mount $backupFolder"; + $failed = $TRUE; + $failedMsg = "Unable to determine type of backup: disk or partition"; + } + } else { + $failed = $TRUE; + $failedMsg = "Unable to mount $backupFolder"; + } + unless ($failed) { + for ($i = 3; $i <= $#config; $i++) { + $uuid = $config[$i]; + #printf "looking at partition=$uuid\n"; + $disk = ""; + $tmp = `ls -l /dev/disk/by-uuid/ | grep -i $uuid`; + #printf "by uuid returned $tmp\n"; + $tmp =~ /\.\.\/\.\.\/(.+)/i; + $disk = $1; + if ($saveDisk && length $disk) { + $lspath = `ls -l /dev/disk/by-path/ | grep -i $disk`; + $lspath =~ /.*:\d\d (.+)-part.*/; + $pth = $1; + $disk = ""; + #printf "by path = $pth\n"; + if (length $pth) { + $lspath = `ls -l /dev/disk/by-path/ | grep -i $pth`; + $lspath =~ /.* -> \.\.\/\.\.\/(.+)/; + $disk = $1; + } + } + #printf "source disk=$disk\n"; + if (length $disk) { + printf "uuid $uuid points to $disk\n"; + $target .= ' ' . $disk; + } } - unless ($failed) { - for ($i = 3; $i <= $#config; $i++) { - chomp $config[$i]; - $uuid = $config[$i]; -#printf "looking at partition=$uuid\n"; - $disk = ""; - $tmp = `ls -l /dev/disk/by-uuid/ | grep -i $uuid`; -#printf "by uuid returned $tmp\n"; - $tmp =~ /\.\.\/\.\.\/(.+)/i; - $disk = $1; - if ($saveDisk && length $disk) { - $lspath = `ls -l /dev/disk/by-path/ | grep -i $disk`; - $lspath =~ /.*:\d\d (.+)-part.*/; - $pth = $1; - $disk = ""; -#printf "by path = $pth\n"; - if (length $pth) { - $lspath = `ls -l /dev/disk/by-path/ | grep -i $pth`; - $lspath =~ /.* -> \.\.\/\.\.\/(.+)/; - $disk = $1; - } - } -#printf "source disk=$disk\n"; - if (length $disk) { - printf "uuid $uuid points to $disk\n"; - $target .= ' ' . $disk; - } - } - if (length $target) { - $cmd = "ocs-sr " . $config[2] . $target; - printf "Running Clonezilla with '$cmd'\n"; - exec($cmd); - } - $failed = $TRUE; - $failedMsg = "Unable to determine backup target partition(s)"; + if (length $target) { + $cmd = "ocs-sr " . $config[2] . $target; + printf "Running Clonezilla with '$cmd'\n"; + exec($cmd); # Does not return from this call to clonezilla } -} else { $failed = $TRUE; - $failedMsg = "Backup configration file was not found"; + $failedMsg = "Unable to determine backup target partition(s)"; + } +} else { + $failed = $TRUE; + $failedMsg = "Backup configuration file was not found"; } if ($failed) { - printf "%s\n", $failedMsg; - printf "\nLaunching Interactive Clonezilla in 10 seconds...\n"; - system("sleep 10"); - exec("ocs-live-general"); + printf "%s\n", $failedMsg; + printf "\nLaunching interactive Clonezilla in 10 seconds...\n"; + system("sleep 10"); + exec("ocs-live-general"); } diff --git a/target_pc/backup-sample.conf b/target_pc/clonezilla-autobackup.conf.sample similarity index 65% rename from target_pc/backup-sample.conf rename to target_pc/clonezilla-autobackup.conf.sample index 55973db..4aa8382 100644 --- a/target_pc/backup-sample.conf +++ b/target_pc/clonezilla-autobackup.conf.sample @@ -1,5 +1,6 @@ # Backup configuration file -# DELETE ALL COMMENTS IN THE REAL FILE +# Comments start with a hash sign, like these lines here +# Empty lines are ignored # should be available in the root of /home/config (mounted from the kernel startup parameters). # Format # line 1: Machine_UUID @@ -10,13 +11,19 @@ # line N: target_uuidN # # Where -# Machine_UUID is the uuid obtained via 'lshw -quiet | grep configuration | grep uuid -# home_partimag_partition_uuid is UUID of the partition which is going to be mounted to /home/partimag for backup -# target_uuidN is uuid of the partition to be backed up (in case of saveparts), or disk to be backed up (in case of savedisk) +# Machine_UUID is the uuid obtained via 'lshw -quiet | grep configuration | grep uuid +# home_partimag_partition_uuid is UUID of the partition which is going to be mounted to /home/partimag for backup +# target_uuidN is uuid of the partition to be backed up (in case of saveparts), or disk to be backed up (in case of savedisk) -# Server +# Server PC 00000000-0000-0000-0000-001FD081B7C9 + +# Target disk UUID 38d9e8cd-deda-4735-ad97-a795665e77fe + +# clonezilla options -q2 -j2 -nogui -z1p -i 2000000 -p poweroff saveparts main_system_partition + +# Source disk/partition UUID 406f5967-271b-4b89-8f37-cdf1ec21a69a