Skip to content

Commit

Permalink
Writes false *source* partition for NVMe backups
Browse files Browse the repository at this point in the history
Writes the source partitions in the form of 'sdzC' when backing up NVMe drives,
rather than writing actual source partition (in the form 'nvmeAnBpC'). This
makes a backup created from an NVMe drive using the next Rescuezilla release
(v1.0.5.1) able to successfully be restored to a non-NVMe drive using
Rescuezilla v1.0.5.

The reason for this is Rescuezilla backup and restore operations processes the
source and destination partitions, and v1.0.5 did not support device nodes in
the pattern nvmeAnBpC.

The source partition written to the backup does not really matter: it may have
some usefulness to a end user, but its use in Rescuezilla is just to extract
the each partition number. Therefore to maximize compatibility and restoring
backups with different versions of Rescuezilla as far as practical, the source
partition may as well be written as 'sdzC', rather than the backup file
containing a list of the source partitions in the form 'nvmeAnBpC'.

Please note, the base device 'sdz' has no special significance other than being
the 26th SATA/SCSI/SAS/USB hard drive in the system (which is unlikely to be
present). Also the fact that 'sdz' is unlikely to be present in the system
helps avoid the "accidental unmount of source partition" issue detailed in
issue rescuezilla#36, which has been fixed for the next Rescuezilla release (v1.0.5.1) but
was present in v1.0.5. Again, see issue rescuezilla#36 for full details.

Fixes rescuezilla#27
  • Loading branch information
shasheene committed Feb 26, 2020
1 parent 0da8673 commit 687acae
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/livecd/chroot/usr/local/sbin/rescuezilla
Expand Up @@ -381,9 +381,7 @@ sub do_backup {
print "\t* ".loc("Size of [_1] ([_2] bytes) saved to [_3]",$src_drive,$bytes,$file_size_path)."\n";
# Save list of partitions we will be backing up
my @partlist = get_selected_partitions('backup_partitions');
my $partlist_str = join("\n", @partlist);
my $file_backup_path = "$dest/$file.backup";
save_file($partlist_str, $file_backup_path);
save_partition_list(\@partlist, "$dest/$file.backup");
# Get the total bytes we're going to be saving
#print Dumper(%drives);
my $total_bytes = 0;
Expand All @@ -402,7 +400,6 @@ sub do_backup {
$status{'done_bytes'} = 0;
$status{'frame'} = 0;
$status{'free'} = get_free_space();
print "\t* ".loc("Partition list saved to [_1]",$file_backup_path)."\n";
# Create backup by calling progress sub
print "\t* ".loc("Total partitions to save: [_1]",$status{'total_parts'})."\n";
print "\t* ".loc("Total bytes to save: [_1]",$status{'total_bytes'})."\n";
Expand Down Expand Up @@ -1978,6 +1975,36 @@ sub join_device_string {
return $joined;
}

sub save_partition_list {
# Takes an array containing a list of partitions and saves it to an output file. More recent device node patterns,
# such as NVMe drives' nvmeAnBpC are rewritten in the format sdzC to preserve the compatibility of Rescuezilla v1.0.5
# to be able to restore NVMe partitions to non-NVMe drives as it processes the source partition list during a
# restore operation.
#
# Input arguments:
# partition array: An array containing the partitions being backed up. Eg, 'sda1', 'sda2', 'sda3'.
# output file: Output file to write the partitions separated by a newline (\n)
my @partitions = @{$_[0]};
my $output_file = $_[1];

foreach my $part (@partitions) {
# During a restore process, the original partition string is processed. Given Rescuezilla v1.0.5 does not
# support the NVMe drive pattern (nvmeAnBpC), rewriting any NVMe drive patterns to an sdzC pattern means that
# Rescuezilla v1.0.5 is able to restore partitions which were originally backed up from an NVMe devices by
# newer version of Rescuezilla.
if ($part =~ /nvme.*/) {
my ($original_base_device, $original_partition_number) = split_device_string($part);
$part = join_device_string("sdz", $original_partition_number);
}
}

# Convert array into string with line breaks after each partition
my $linebroken_partition_string = join("\n", @partitions);
save_file($linebroken_partition_string, $output_file);
print "\t* ".loc("Partition list saved to [_1]",$file_backup_path)."\n";
}


sub get_drivetype {
# Given an "sdX" device, return the string that indicates its type
my $dev = $_[0];
Expand Down

0 comments on commit 687acae

Please sign in to comment.