Skip to content
Merged
Changes from all commits
Commits
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
55 changes: 52 additions & 3 deletions lgsm/modules/command_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,74 @@ fn_select_compression() {
fi
}

# Game data kept outside rootdir, such as worlds saved under the home directory.
fn_backup_extradirs() {
local candidates=()
local covered=() dir dirreal link coveredpath
backupextradirs=()
if [ "${shortname}" == "bt" ]; then
candidates+=("${XDG_DATA_HOME:-${HOME}/.local/share}/Daedalic Entertainment GmbH/Barotrauma")
elif [ "${shortname}" == "ct" ]; then
candidates+=("${serverfiles}DedicatedServerSave")
elif [ "${shortname}" == "dst" ]; then
candidates+=("${persistentstorageroot}")
elif [ "${shortname}" == "pz" ]; then
candidates+=("${HOME}/Zomboid")
elif [ "${shortname}" == "scpsl" ]; then
candidates+=("${HOME}/.config/SCP Secret Laboratory/config")
elif [ "${shortname}" == "sdtd" ]; then
candidates+=("${HOME}/.local/share/7DaysToDie/Saves")
fi
candidates+=("${savedir}" "${servercfgdir}")
covered+=("$(readlink -f "${rootdir}")")
while IFS= read -r link; do
covered+=("$(readlink -f "${link}")")
done < <(find "${rootdir}" -maxdepth 2 -type l 2> /dev/null)
for dir in "${candidates[@]}"; do
if [ -z "${dir}" ] || [ ! -d "${dir}" ]; then
continue
fi
dirreal="$(readlink -f "${dir}")"
for coveredpath in "${covered[@]}" "${backupextradirs[@]}"; do
if [[ "${dirreal}/" == "${coveredpath}/"* ]]; then
continue 2
fi
done
backupextradirs+=("${dirreal}")
done
}

# Compressing files.
fn_backup_compression() {
fn_backup_extradirs
backupextras=()
for extradir in "${backupextradirs[@]}"; do
echo -e "* Including ${extradir}"
fn_script_log_info "Including ${extradir}"
backupextras+=(-C / "${extradir#/}")
done

fn_print_info "A total of ${rootdirduexbackup} will be compressed."
fn_script_log_info "A total of ${rootdirduexbackup} will be compressed: ${backupdir}/${backupname}.${compressext}"
fn_print_dots "Backup (${rootdirduexbackup}) ${backupname}.${compressext}, in progress ..."
fn_script_log_info "Backup ${rootdirduexbackup} ${backupname}.${compressext}, in progress"
excludedir=$(fn_backup_relpath)

if [ ! -d "${excludedir}" ]; then
if [ ! -d "${rootdir}/${excludedir}" ]; then
fn_print_fail_nl "Problem identifying the previous backup directory for exclusion."
fn_script_log_fail "Problem identifying the previous backup directory for exclusion"
core_exit.sh
fi

backupexcludes=(--exclude "${excludedir}" --exclude "${lockdir}" --exclude "${tmpdir}")
if [[ "${backupdir}" == "${rootdir}/"* ]]; then
backupexcludes+=(--exclude "./${backupdir#"${rootdir}"/}")
fi

if [ -n "${compressflag}" ]; then
tar ${compressflag} -hcf "${backupdir}/${backupname}.${compressext}" -C "${rootdir}" --exclude "${excludedir}" --exclude "${lockdir}" --exclude "${tmpdir}" ./.
tar ${compressflag} -hcf "${backupdir}/${backupname}.${compressext}" "${backupexcludes[@]}" -C "${rootdir}" ./. "${backupextras[@]}"
else
tar -hcf "${backupdir}/${backupname}.${compressext}" -C "${rootdir}" --exclude "${excludedir}" --exclude "${lockdir}" --exclude "${tmpdir}" ./.
tar -hcf "${backupdir}/${backupname}.${compressext}" "${backupexcludes[@]}" -C "${rootdir}" ./. "${backupextras[@]}"
fi

exitcode=$?
Expand Down
Loading