From ea086552887bb8561cbf1f2bd15e77f9c056fca7 Mon Sep 17 00:00:00 2001 From: Weisson Date: Thu, 5 Jan 2023 23:00:30 +0800 Subject: [PATCH] Basic backup and recovery support for ARM platform. Signed-off-by: Weisson --- migrear | 29 +++++++++++++++++++++++++---- migrear-install.sh | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/migrear b/migrear index 865975c..b636a53 100644 --- a/migrear +++ b/migrear @@ -36,6 +36,13 @@ class NotRootPathException(Exception): self.message = message.format(path) super().__init__(self.message) + +class ArchitectureNotSupportException(Exception): + def __init__(self, arch, message="Architecture '{}' is not support for migrear."): + self.message = message.format(arch) + super().__init__(self.message) + + def p64(n: int) -> str: table = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_" s = bin(n)[2:][::-1] @@ -92,16 +99,26 @@ def backup(method, initramfs_path, initramfs_url, layout_path, layout_url, host_ check_call("umount " + tmp_mountponit) raise HashCollisionException() + arch = platform.machine() + if arch in ["x86_64"]: + initrd_mode = "RAMDISK" + elif arch in ["aarch64", "aarch64_be", "arm", "armv8b", "armv8l"]: + initrd_mode = "PXE" + initramfs_url = "/".join([initramfs_url, '$HOSTNAME-' + hash]) + else: + raise ArchitectureNotSupportException(arch=arch) + local_cfg = """ -OUTPUT=RAMDISK +OUTPUT=%s OUTPUT_URL=%s +PXE_TFTP_PREFIX=$HOSTNAME-%s- BACKUP=NETFS BACKUP_URL=%s BACKUP_PROG_EXCLUDE=("\$\{BACKUP_PROG_EXCLUDE[@]\}" '/media' '/var/tmp' '/var/crash' %s '/tmp/*') NETFS_KEEP_OLD_BACKUP_COPY= NETFS_PREFIX="$HOSTNAME-%s" RAMDISK_SUFFIX="%s" -""" % (initramfs_url, layout_url, " ".join(excludes), hash, hash) +""" % (initrd_mode, initramfs_url, hash, layout_url, " ".join(excludes), hash, hash) with open("/etc/rear/local.conf", "w") as f: f.write(local_cfg) @@ -122,8 +139,12 @@ RAMDISK_SUFFIX="%s" # grub vmlinuz = check_output("ls /boot/vmlinuz-$(uname -r)").strip() - initramfs_file_path = check_output("find %s -name 'initramfs-%s.img'" % (initramfs_path, hash)) - command = "grubby --add-kernel %s --initrd %s --title MigReaR-%s " % (vmlinuz, initramfs_file_path, hash) + if initrd_mode == "RAMDISK": + initramfs_file_path = check_output("find %s -name 'initramfs-%s.img'" % (initramfs_path, hash)) + elif initrd_mode == "PXE": + initramfs_file_path = check_output("find %s -name '%s-%s-initrd.cgz'" % (initramfs_path, platform.node(), hash)) + + command = "grubby --add-kernel %s --initrd %s --title MigReaR-%s --copy-default" % (vmlinuz, initramfs_file_path, hash) if method == "nfs": args = " --args='ro console=tty0 console=ttyS0,115200n8 console=ttyS0 unattended'" elif method == "local": diff --git a/migrear-install.sh b/migrear-install.sh index dcb8e18..ff50382 100644 --- a/migrear-install.sh +++ b/migrear-install.sh @@ -2,6 +2,6 @@ yum install rear genisoimage syslinux nfs-utils python3 wget -y -wget https://gitee.com/src-anolis-sig/leapp-repository/raw/wip_migrear/migrear -O /usr/sbin/migrear +wget https://gitee.com/Weisson/leapp-repository/raw/wip_migrear/migrear -O /usr/sbin/migrear chmod +x /usr/sbin/migrear -- Gitee