incremental improvement in backup/restore facility

master
phanes 2023-02-26 17:19:40 -05:00
parent 05c65e8d1d
commit b513be8d4d
6 changed files with 241 additions and 3 deletions

View File

@ -77,9 +77,13 @@ build_stage3:
sudo /usr/bin/env -i bash -c ". ./project_config.sh && ${dir_make}/build_stage3.sh" sudo /usr/bin/env -i bash -c ". ./project_config.sh && ${dir_make}/build_stage3.sh"
# offers to back up # offers to back up
build_stage4backup: backup:
set -e set -e
sudo /usr/bin/env -i bash -c ". ./project_config.sh && ${dir_make}/build_stage4backup.sh" sudo /usr/bin/env -i bash -c ". ./project_config.sh && ${dir_make}/backup_create.sh"
restore_backup:
set -e
sudo bash -c ". ./project_config.sh && ${dir_make}/backup_restore.sh"
build_stage4: build_stage4:
set -e set -e
@ -110,7 +114,7 @@ all:
make build_stage1 && \ make build_stage1 && \
make build_stage2 && \ make build_stage2 && \
make build_stage3 && \ make build_stage3 && \
make build_stage4backup && \ make backup && \
make build_stage4 make build_stage4

107
make.project/backup_restore.sh Executable file
View File

@ -0,0 +1,107 @@
#!/usr/bin/env bash
# fix an issue with open files limit on some hosts
ulimit -l unlimited
#ulimit -n 10240
ulimit -c unlimited
T_SYSROOT=${dir_sysroot}
#!/bin/bash
# move this to the makefile as a dedicated target
APPNAME="Offer Backup"
# ISO 8601 variation
TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)"
LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}"
# the file to log to
LOGFILE="${APPNAME}.log"
logprint() {
mkdir -p "${LOG_DIR}"
echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \
| tee -a "${LOG_DIR}/${LOGFILE}"
}
logprint "Giving the user the option of backing up before proceeding."
is_mounted() {
findmnt $1 &> /dev/null
if [ $? != 0 ]; then
logprint "Not mounted...skipping."
/usr/bin/false
else
logprint "Mounted..."
/usr/bin/true
fi
}
function disarm_chroot() {
logprint "Unmounting CHROOT VFKS mounts"
logprint "Unmounting ${T_SYSROOT}/dev"
is_mounted ${T_SYSROOT}/dev && umount -l ${T_SYSROOT}/dev
logprint "Unmounting ${T_SYSROOT}/dev/pts"
is_mounted ${T_SYSROOT}/dev/pts && umount -l ${T_SYSROOT}/dev/pts
logprint "Unmounting ${T_SYSROOT}/proc"
is_mounted ${T_SYSROOT}/proc && umount -l ${T_SYSROOT}/proc
# not a symlink on ubuntu
logprint "Unmounting ${T_SYSROOT}/dev/shm"
is_mounted ${T_SYSROOT}/dev/shm && umount -l ${T_SYSROOT}/dev/shm
logprint "Unmounting pyrois inside of chroot"
is_mounted ${T_SYSROOT}/rex_embedded && umount -l ${T_SYSROOT}/rex_embedded
}
function clear_stage() {
pushd ${project_root}
make clean
}
function restore() {
# select a backup file
FILE=$(dialog --title "Choose a restore point." --stdout --title "Please choose an archive to restore from." --fselect ${project_root} 14 48)
[ ! -z $FILE ] || logprint "User canceled restore." && exit 0
logprint "Entering backup routine. Clearing stage."
clear_stage
logprint "Restoring backup...This will take a long time..."
tar xphf $FILE
assert_zero $?
logprint "Backup restored successfully. Arming chroot."
pushd ${project_root}
assert_zero $?
make arm_chroot
echo
logprint "You may now proceed to run 'make build_stage4' or higher."
echo
}
read -r -d '' yn_msg <<-'EOF'
Restore from backup?
EOF
# Use the dialog utility to prompt the user with a yes/no question
dialog --backtitle "Dark Horse Linux: Pyrois" --title "Restore From Backup" --yesno "$yn_msg" 10 60
response=$?
if [ $response -eq 0 ]; then
logprint "User selected to perform backups."
restore
else
logprint "User canceled. Moving on."
exit 0
fi

View File

@ -0,0 +1,95 @@
#!/bin/bash
# move this to the makefile as a dedicated target
APPNAME="Offer Backup"
# ISO 8601 variation
TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)"
LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}"
# the file to log to
LOGFILE="${APPNAME}.log"
logprint() {
mkdir -p "${LOG_DIR}"
echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \
| tee -a "${LOG_DIR}/${LOGFILE}"
}
logprint "Giving the user the option of backing up before proceeding."
is_mounted() {
findmnt $1 &> /dev/null
if [ $? != 0 ]; then
logprint "Not mounted...skipping."
/usr/bin/false
else
logprint "Mounted..."
/usr/bin/true
fi
}
function disarm_chroot() {
logprint "Unmounting CHROOT VFKS mounts"
logprint "Unmounting ${T_SYSROOT}/dev"
is_mounted ${T_SYSROOT}/dev && umount -l ${T_SYSROOT}/dev
logprint "Unmounting ${T_SYSROOT}/dev/pts"
is_mounted ${T_SYSROOT}/dev/pts && umount -l ${T_SYSROOT}/dev/pts
logprint "Unmounting ${T_SYSROOT}/proc"
is_mounted ${T_SYSROOT}/proc && umount -l ${T_SYSROOT}/proc
# not a symlink on ubuntu
logprint "Unmounting ${T_SYSROOT}/dev/shm"
is_mounted ${T_SYSROOT}/dev/shm && umount -l ${T_SYSROOT}/dev/shm
logprint "Unmounting pyrois inside of chroot"
is_mounted ${T_SYSROOT}/rex_embedded && umount -l ${T_SYSROOT}/rex_embedded
}
function clear_stage() {
pushd ${project_root}
make clean
}
function restore() {
# select a backup file
FILE=$(dialog --title "Choose a restore point." --stdout --title "Please choose an archive to restore from." --fselect ${project_root} 14 48)
logprint "Entering backup routine."
disarm_chroot
disarm_chroot
logprint "Restoring backup...This will take a long time..."
tar xpf $FILE
assert_zero $?
logprint "Backup restored successfully. Arming chroot."
pushd ${project_root}
assert_zero $?
make arm_chroot
echo
logprint "You may now proceed to run 'make build_stage4' or higher."
echo
}
read -r -d '' yn_msg <<-'EOF'
Restore from backup?
EOF
# Use the dialog utility to prompt the user with a yes/no question
dialog --backtitle "Dark Horse Linux: Pyrois" --title "Restore From Backup" --yesno "$yn_msg" 10 60
response=$?
if [ $response -eq 0 ]; then
logprint "User selected to perform backups."
restore
else
logprint "User canceled. Moving on."
exit 0
fi

View File

@ -0,0 +1,10 @@
{
"plan":
[
{
"name": "restore backup",
"dependencies": [ null ],
"comment": "LFS 11.3-systemd-rc1 Ch. 7.13.2"
}
]
}

View File

@ -0,0 +1,22 @@
{
"units": [
{
"name": "restore backup",
"target": "components/stage4backup/restore_backup.bash",
"is_shell_command": true,
"shell_definition": "bash",
"force_pty": true,
"set_working_directory": false,
"working_directory": "",
"rectify": false,
"rectifier": "",
"active": true,
"required": true,
"set_user_context": true,
"user": "root",
"group": "root",
"supply_environment": true,
"environment": "environments/stage2.env.bash"
}
]
}