BackupVolume copies a volume (and optionally its snapshots) to a specified target path. This driver does not support optimized backups.
(vol Volume, writer instancewriter.InstanceWriter, basePrefix string, optimized bool, snapshots []string, op *operations.Operation)
| 1696 | // BackupVolume copies a volume (and optionally its snapshots) to a specified target path. |
| 1697 | // This driver does not support optimized backups. |
| 1698 | func (d *btrfs) BackupVolume(vol Volume, writer instancewriter.InstanceWriter, basePrefix string, optimized bool, snapshots []string, op *operations.Operation) error { |
| 1699 | // Handle the non-optimized tarballs through the generic packer. |
| 1700 | if !optimized { |
| 1701 | // Because the generic backup method will not take a consistent backup if files are being modified |
| 1702 | // as they are copied to the tarball, as BTRFS allows us to take a quick snapshot without impacting |
| 1703 | // the parent volume we do so here to ensure the backup taken is consistent. |
| 1704 | if vol.contentType == ContentTypeFS { |
| 1705 | snapshotPath, cleanup, err := d.readonlySnapshot(vol) |
| 1706 | if err != nil { |
| 1707 | return err |
| 1708 | } |
| 1709 | |
| 1710 | // Clean up the snapshot. |
| 1711 | defer cleanup() |
| 1712 | |
| 1713 | // Set the path of the volume to the path of the fast snapshot so the migration reads from there instead. |
| 1714 | vol.mountCustomPath = snapshotPath |
| 1715 | } |
| 1716 | |
| 1717 | return genericVFSBackupVolume(d, vol, writer, basePrefix, snapshots, op) |
| 1718 | } |
| 1719 | |
| 1720 | // Optimized backup. |
| 1721 | |
| 1722 | if len(snapshots) > 0 { |
| 1723 | // Check requested snapshot match those in storage. |
| 1724 | err := vol.SnapshotsMatch(snapshots, op) |
| 1725 | if err != nil { |
| 1726 | return err |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | // Generate driver restoration header. |
| 1731 | optimizedHeader, err := d.restorationHeader(vol, snapshots) |
| 1732 | if err != nil { |
| 1733 | return err |
| 1734 | } |
| 1735 | |
| 1736 | // Convert to YAML. |
| 1737 | optimizedHeaderYAML, err := yaml.Dump(&optimizedHeader, yaml.WithV2Defaults()) |
| 1738 | if err != nil { |
| 1739 | return err |
| 1740 | } |
| 1741 | |
| 1742 | r := bytes.NewReader(optimizedHeaderYAML) |
| 1743 | |
| 1744 | indexFileInfo := instancewriter.FileInfo{ |
| 1745 | FileName: filepath.Join(basePrefix, "optimized_header.yaml"), |
| 1746 | FileSize: int64(len(optimizedHeaderYAML)), |
| 1747 | FileMode: 0o644, |
| 1748 | FileModTime: time.Now(), |
| 1749 | } |
| 1750 | |
| 1751 | // Write to tarball. |
| 1752 | err = writer.WriteFileFromReader(r, &indexFileInfo) |
| 1753 | if err != nil { |
| 1754 | return err |
| 1755 | } |
nothing calls this directly
no test coverage detected