aboutsummaryrefslogtreecommitdiffstats
path: root/chapter6/backup.sh
blob: 837c44c352278122b5a3c1d029eee007b596bc1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
set -e

file="${LFS_VER}-ch6-backup.tar.xz"
directories=(bin etc lib lib64 sbin tools usr var)

if [ -f "${LFS}/sources/chapter6/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/chapter6/backup.log 2>&1 & pid=$!
	spinner "$pid" "${SPINNER}"
	retval=$?
	if [ "$retval" -ne 0 ]; then
		printf "%b" "${IRED}FAILED!${RST}\n"
		exit "${retval}"
	else
		# shellcheck disable=SC2024
		sudo chown -v "${USER}":"$(id -g)" "${HOME}"/"${file}" >>"${LFS}"/sources/log/chapter6/backup.log
		printf "%b" "${IGRN}OK${RST}\n"
	fi
	popd > /dev/null || exit 1

	touch "${LFS}"/sources/chapter6/backup
fi