aboutsummaryrefslogtreecommitdiffstats
path: root/chapter8/backup.sh
diff options
context:
space:
mode:
authorWilliam Harrington <kb0iic@berzerkula.org>2021-04-12 12:49:29 -0500
committerWilliam Harrington <kb0iic@berzerkula.org>2021-04-12 12:49:29 -0500
commit99659c30e5369c3f02e286a4a6ec6fecd77f0416 (patch)
tree12110b15571365acae602ebd9c1348463a0d4710 /chapter8/backup.sh
parent0e5288f8f3bee7276d561cde029ed492e2ea85e6 (diff)
parent13c6afd35cab1e3f4d96857d549e02cfd1e23acd (diff)
Merge branch 'chapter8'
Diffstat (limited to 'chapter8/backup.sh')
-rw-r--r--chapter8/backup.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/chapter8/backup.sh b/chapter8/backup.sh
new file mode 100644
index 0000000..8d750c5
--- /dev/null
+++ b/chapter8/backup.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+file="${LFS_VER}-ch8-backup.tar.xz"
+directories=(bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var)
+
+if [ -f "${LFS}/sources/chapter8/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/chapter8/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/chapter8/backup.log 2>&1
+ printf "%b" "${IGRN}OK${RST}\n"
+ fi
+ popd > /dev/null || exit 1
+
+ touch "${LFS}/sources/chapter8/backup"
+fi