BastilleBSD / bastille

Bastille is an open-source system for automating deployment and management of containerized applications on FreeBSD.
https://bastillebsd.org
BSD 3-Clause "New" or "Revised" License
854 stars 137 forks source link

[BUG] Bastille export is failing #722

Open jemail99 opened 1 month ago

jemail99 commented 1 month ago

[MANDATORY] Describe the bug [MANDATORY] Using the bastille docs example fails (using my own jail name)

bastille export radicale
Error: export option required

Also

bastille export --xz radicale
Error: export option required

However the following work

bastille export --tgz radicale
bastille export --txz radicale

[MANDATORY] Bastille and FreeBSD version (paste bastille -v && freebsd-version -kru output) 0.10.20231125 14.1-RELEASE-p5 14.1-RELEASE-p5 14.1-RELEASE-p5

[MANDATORY] How did you install bastille? (port/pkg/git) Installed from pkg

[optional] Expected behavior Expect bastille to export the jail using default settings and using --xz option

[optional] Additional context Running Freebsd on Raspberry pi4 8gb using UFS as the filesystem.

tschettervictor commented 5 days ago

Are you using zfs? Looking at the export.sh script it looks like if “bastille_zfs_enable” is not activated it will not even process the “XZ_EXPORT” variable, and will therefore error out.

jemail99 commented 4 days ago

Hello, I'm using UFS only not ZFS. I assumed that bastille was compatible with UFS and ZFS?

tschettervictor commented 4 days ago

It is compatible with UFS. But if you look at the code below, you will see that it will not even register the XZ_EXPORT variable if "bastille_zfs_enable" is not active. Maybe that is by design and XZ_EXPORT is not supported if you run on UFS.

jail_export() {
    # Attempt to export the container
    DATE=$(date +%F-%H%M%S)
    if checkyesno bastille_zfs_enable; then
        if [ -n "${bastille_zfs_zpool}" ]; then
            if [ -n "${RAW_EXPORT}" ]; then
                FILE_EXT=""
                export_check

                # Export the raw container recursively and cleanup temporary snapshots
                zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" \
                > "${bastille_backupsdir}/${TARGET}_${DATE}"
                clean_zfs_snap
            elif [ -n "${GZIP_EXPORT}" ]; then
                FILE_EXT=".gz"
                export_check

                # Export the raw container recursively and cleanup temporary snapshots
                zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" | \
                gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
                clean_zfs_snap
            elif [ -n "${XZ_EXPORT}" ]; then
                FILE_EXT=".xz"
                export_check

                # Export the container recursively and cleanup temporary snapshots
                zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" | \
                xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
                clean_zfs_snap
            else
                FILE_EXT=""
                USER_EXPORT="1"
                export_check

                # Quietly export the container recursively, user must redirect standard output
                if ! zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"; then
                    clean_zfs_snap
                    error_notify "\nError: An export option is required, see 'bastille export, otherwise the user must redirect to standard output."
                fi
            fi
        fi
    else
        if [ -n "${TGZ_EXPORT}" ]; then
            FILE_EXT=".tgz"

            # Create standard tgz backup archive
            info "Exporting '${TARGET}' to a compressed ${FILE_EXT} archive..."
            cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
        elif [ -n "${TXZ_EXPORT}" ]; then
            FILE_EXT=".txz"

            # Create standard txz backup archive
            info "Exporting '${TARGET}' to a compressed ${FILE_EXT} archive..."
            cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
        else
            error_exit "Error: export option required"
        fi
    fi

    if [ "$?" -ne 0 ]; then
        error_exit "Failed to export '${TARGET}' container."
    else
        if [ -z "${USER_EXPORT}" ]; then
            # Generate container checksum file
            cd "${bastille_backupsdir}"
            sha256 -q "${TARGET}_${DATE}${FILE_EXT}" > "${TARGET}_${DATE}.sha256"
            info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}' successfully."
        fi
        exit 0
    fi
}
jemail99 commented 4 days ago

It's possible I don't know the reasons why xz is limited to zfs. However xz compression is available on FreeBSD 14.1 and can be executed on UFS :shrug:

xz --version
xz (XZ Utils) 5.4.5
liblzma 5.4.5
tschettervictor commented 4 days ago

The devs will have to answer that question. I'm just pointing to the reason why it is failing.

tschettervictor commented 3 days ago

xz and txz do the exact same thing anyway, just that xz does zfs specific stuff, so I’d recommend just using txz