Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DietPi-Backup | Add Option to Automatically Restore on First Boot #4112

Merged
merged 36 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4fdd52c
v6.35
ravenclaw900 Feb 8, 2021
bb12c5b
v7.1
ravenclaw900 Feb 15, 2021
bd6e36e
v7.1
ravenclaw900 Feb 15, 2021
794eaff
v7.1
ravenclaw900 Feb 15, 2021
580856c
v7.0
ravenclaw900 Feb 15, 2021
365b8f5
v7.0
ravenclaw900 Feb 15, 2021
86d390d
v7.0
ravenclaw900 Feb 15, 2021
05dfa8c
v7.0
ravenclaw900 Feb 15, 2021
d8cc428
v7.0
ravenclaw900 Feb 15, 2021
ac013ae
v7.0
ravenclaw900 Feb 15, 2021
5369ff6
v7.0
ravenclaw900 Feb 15, 2021
a0ed620
v7.0
ravenclaw900 Feb 15, 2021
5b3c2b9
v7.0 (#4113)
MichaIng Feb 15, 2021
a6f805d
v7.0
ravenclaw900 Feb 15, 2021
74a34e6
Merge branch 'restore-boot' of https://github.com/MichaIng/DietPi int…
ravenclaw900 Feb 15, 2021
2094d45
v7.0
ravenclaw900 Feb 15, 2021
df2015f
v7.0
ravenclaw900 Feb 15, 2021
a5ef5a4
v7.0
MichaIng Feb 15, 2021
1642376
v7.0
MichaIng Feb 15, 2021
de3df2a
v7.0
MichaIng Feb 15, 2021
820d82e
v7.0
MichaIng Feb 15, 2021
60cce61
v7.0
MichaIng Feb 15, 2021
5fbd2fa
v7.0
MichaIng Feb 15, 2021
59b5c0c
Merge branch 'dev' into restore-boot
ravenclaw900 Feb 17, 2021
ce0ed5e
v7.0 (#4120)
MichaIng Feb 17, 2021
5b1abee
Merge branch 'dev' into restore-boot
MichaIng Feb 22, 2021
f5519ea
v7.0
MichaIng Feb 22, 2021
274fe91
v7.0
MichaIng Feb 24, 2021
1f9ebb3
v7.0
MichaIng Feb 24, 2021
144007d
v7.0
MichaIng Feb 26, 2021
7721577
v7.0
MichaIng Feb 26, 2021
9ecd07a
Update restore-boot branch (#4143)
MichaIng Feb 26, 2021
8a435fd
v7.0
MichaIng Feb 26, 2021
ecbe1b7
v7.0
MichaIng Feb 26, 2021
19a7219
v7.0
MichaIng Feb 26, 2021
7a113e7
v7.0
MichaIng Feb 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dietpi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ AUTO_UNMASK_LOGIND=0
# - Executed script log: /var/tmp/dietpi/logs/dietpi-automation_custom_script.log
AUTO_SETUP_CUSTOM_SCRIPT_EXEC=0

# - Restore a DietPi-Backup on first boot: 0 => disable | 1 => interactive restore (show list of drives) | 2 => non-interactive restore (restore from first found drive)
AUTO_SETUP_BACKUP_RESTORE=0

##### Software Options #####
# SSH Server Selection: 0=none/custom | -1=Dropbear | -2=OpenSSH
AUTO_SETUP_SSH_SERVER_INDEX=-1
Expand Down
53 changes: 53 additions & 0 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -16255,6 +16255,7 @@ _EOF_
AUTOINSTALL_WEBSERVERINDEX=$(sed -n '/^[[:blank:]]*AUTO_SETUP_WEB_SERVER_INDEX=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
AUTOINSTALL_CUSTOMSCRIPTURL=$(sed -n '/^[[:blank:]]*AUTO_SETUP_CUSTOM_SCRIPT_EXEC=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
AUTOINSTALL_TIMESYNCMODE=$(sed -n '/^[[:blank:]]*CONFIG_NTP_MODE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
AUTOINSTALL_RESTORE=$(sed -n '/^[[:blank:]]*AUTO_SETUP_BACKUP_RESTORE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
# Else set defaults
[[ $AUTOINSTALL_ENABLED ]] || AUTOINSTALL_ENABLED=0
[[ $AUTOINSTALL_AUTOSTARTTARGET ]] || AUTOINSTALL_AUTOSTARTTARGET=0
Expand All @@ -16264,6 +16265,7 @@ _EOF_
[[ $AUTOINSTALL_WEBSERVERINDEX ]] || AUTOINSTALL_WEBSERVERINDEX=0
[[ $AUTOINSTALL_CUSTOMSCRIPTURL ]] || AUTOINSTALL_CUSTOMSCRIPTURL=0
[[ $AUTOINSTALL_TIMESYNCMODE ]] || AUTOINSTALL_TIMESYNCMODE=2
[[ $AUTOINSTALL_RESTORE ]] || AUTOINSTALL_RESTORE=0

}

Expand Down Expand Up @@ -17651,6 +17653,57 @@ List of installed software and their online documentation URLs:
# Load all automation vars
FirstRun_Automation_Init

if (( $AUTOINSTALL_RESTORE )); then

# Find unmounted drives
lsblk --noheadings --raw -o NAME,MOUNTPOINT | mawk '$1~/s.*[0-9]/ && $2 == ""' > .lsblk_out_tmp
ravenclaw900 marked this conversation as resolved.
Show resolved Hide resolved
i=0
while read -r line
do

# Mount drives to temporary mount points
mkdir "/mnt/dietpi-backup$i"
mount "/dev/$line" "/mnt/dietpi-backup$i"

i++

done < .lsblk_out_tmp
rm .lsblk_out_tmp

mapfile -t alist < <(find /mnt -type f -name "$BACKUP_STATS_FILENAME")
ravenclaw900 marked this conversation as resolved.
Show resolved Hide resolved

if [[ $AUTOINSTALL_RESTORE == 1 ]]; then
# Do we have any results?
if (( ${alist[0]} )); then
# Create List for Whiptail
G_WHIP_MENU_ARRAY=()
for i in "${alist[@]}"
do

last_backup_date=$(sed -n '/ompleted/s/^.*: //p' "$i" | tail -1) # Date of last backup for this backup
backup_directory=${i%/$BACKUP_STATS_FILENAME} # Backup directory (minus the backup file), that we can use for target backup directory.
G_WHIP_MENU_ARRAY+=("$backup_directory" ": $last_backup_date")

done

G_WHIP_MENU 'Please select a previous backup to use:'
/boot/dietpi/dietpi-backup -1 "$G_WHIP_RETURNED_VALUE"

else

G_WHIP_MSG 'No previous backups were found in /mnt/*'
return
fi
elif [[ $AUTOINSTALL_RESTORE == 2 ]]; then
# Do we have any results?
if (( ${alist[0]} )); then
# Restore first found backup
/boot/dietpi/dietpi-backup -1 /mnt/dietpi-backup0
ravenclaw900 marked this conversation as resolved.
Show resolved Hide resolved
fi
ravenclaw900 marked this conversation as resolved.
Show resolved Hide resolved
fi

fi

# Global PW
# - Automation, apply as per dietpi.txt
if (( $AUTOINSTALL_ENABLED )); then
Expand Down