#!/bin/bash set -e file="${LFS_VER}-ch7-backup.tar.xz" directories=(bin dev etc lib lib64 proc run sbin sys tools usr var) if [ -f "${LFS}/sources/chapter7/backup" ]; then printf "%b" " ${IGRN}Backup previously completed${RST}\n" else printf "%b" "${GRN}Backing up ${YLW}${LFS}${GRN} to ${YLW}${file}${RST}... " pushd "${LFS}" > /dev/null || exit 1 # shellcheck disable=SC2024 sudo XZ_OPTS="-T${NUMPROCS} -e" tar cJvpf "${HOME}"/"${file}" "${directories[@]}" >"${LFS}"/sources/log/chapter7/backup.log 2>&1 & pid=$! spinner "$pid" "${SPINNER}" retval=$? if [ "${retval}" -ne 0 ]; then fail "FAILED!" exit "${retval}" else # shellcheck disable=SC2024 sudo chown -v "${USER}":"$(id -g)" "${HOME}"/"${file}" >"${LFS}"/sources/log/chapter7/backup.log 2>&1 success "OK" fi popd > /dev/null || exit 1 touch "${LFS}/sources/chapter7/backup" fi